from urllib.request import urlopen from sopel.module import commands def get_stats(): r = urlopen("http://tor.caspervk.net:44313/vnstat").read().decode() values = r.strip().split(";") keys = ("version", "interface", "today_timestamp", "today_rx", "today_tx", "today_total", "today_avgrate", "month_timestamp", "month_rx", "month_tx", "month_total", "month_avgrate", "total_rx", "total_tx", "total_total") return dict(zip(keys, values)) @commands("tor") def tor(bot, trigger): stats = get_stats() bot.say("Relay statistics for today: {today_rx} received, {today_tx} transmitted for a total of {today_total} at an average rate of {today_avgrate}".format(**stats)) bot.say("Relay statistics for month: {month_rx} received, {month_tx} transmitted for a total of {month_total} at an average rate of {month_avgrate}".format(**stats)) bot.say("Relay statistics totals: {total_rx} received, {total_tx} transmitted for a total of {total_total}".format(**stats))