12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- # -*- coding: utf-8 -*-
- from __future__ import print_function
- import willie
- from ffpb import ffpb_fetch_stats
- def setup(bot):
- """Called by willie upon loading this plugin."""
- try:
- ffpb_hamburg_fetch(bot)
- except:
- pass
- def shutdown(bot):
- """Called by willie upon unloading this plugin."""
- pass
- @willie.module.interval(60)
- def ffpb_hamburg_fetch(bot):
- ffpb_fetch_stats(bot, 'https://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.get('ffhh_stats', None)
- if hamburg_data is None:
- bot.say('Hamburg, was ist schon Hamburg ... zumindest habe ich gerade keine Daten.')
- return
- if not trigger.group(2) is None:
- insane_suffixes = ['rules', 'rulez', 'ist besser', 'siegt', 'ist cool', 'ist die nummer 1', 'vor', 'vorne', 'nr. 1']
- if trigger.group(2).lower() in insane_suffixes:
- bot.msg(trigger.sender, '\x01ACTION %s\x01' % 'bezweifelt das.')
- 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_unique']
- 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,
- ))
|