# -*- 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') if 'ffhh_rueckspiegel' in bot.memory and bot.memory['ffhh_rueckspiegel'] == True: return stats = bot.memory['ffpb_stats'] if 'ffpb_stats' in bot.memory else None hamburg_data = bot.memory['ffhh_stats'] if 'ffhh_stats' in bot.memory else None if not (stats is None or hamburg_data is None): if hamburg_data['nodes_active'] < stats['nodes_active']: print('HAMBURG überholt: {0}<{1}'.format(hamburg_data['nodes_active'], stats['nodes_active'])) bot.memory['ffhh_rueckspiegel'] = True action_msg = u'schaut in den Rückspiegel und erblickt HAMBURG!' action_target = bot.config.ffpb.msg_target if not bot.config.ffpb.msg_target_public is None: action_target = bot.config.ffpb.msg_target_public bot.msg(action_target, '\x01ACTION %s\x01' % action_msg) @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} Knoten (= PB{1:+g}), {2} Clients (= PB{3:+g})'.format(hamburg_data['nodes_active'], diff_nodes, hamburg_data['clients'], diff_clients))