# -*- coding: utf-8 -*- from __future__ import print_function import willie import random import time from ffpb import pretty_date, ffpb_fetch_stats def setup(bot): try: ffpb_hamburg_fetch(bot) except: pass def shutdown(bot): pass @willie.module.interval(60) def ffpb_hamburg_fetch(bot): ffpb_fetch_stats(bot, 'http://hamburg.freifunk.net/nodes_ffhh/nodes.json', 'ffhh_stats') @willie.module.commands('hamburg') def ffpb_hamburg(bot, trigger): hamburg_data = bot.memory['ffhh_stats'] if 'ffhh_stats' in bot.memory else None if hamburg_data is None: bot.say('Hamburg, was ist schon Hamburg ... zumindest habe ich gerade keine Daten.') return stats = bot.memory['ffpb_stats'] if 'ffpb_stats' in bot.memory else None if stats is None: bot.say('Bitte später nochmal fragen :)') return diff_nodes = hamburg_data['nodes_active'] - stats['nodes_active'] diff_clients = hamburg_data['clients'] - stats['clients'] bot.say('Hamburg: {0}{1:+g} Knoten, {2}{3:+g} Clients (Status von {4})'.format(stats['nodes_active'], diff_nodes, stats['clients'], diff_clients, pretty_date(hamburg_data['fetchtime'])))