ffpb_hamburg.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # -*- coding: utf-8 -*-
  2. from __future__ import print_function
  3. import willie
  4. import random
  5. import time
  6. from ffpb import pretty_date, ffpb_fetch_stats
  7. def setup(bot):
  8. try:
  9. ffpb_hamburg_fetch(bot)
  10. except:
  11. pass
  12. def shutdown(bot):
  13. pass
  14. @willie.module.interval(60)
  15. def ffpb_hamburg_fetch(bot):
  16. ffpb_fetch_stats(bot, 'http://hamburg.freifunk.net/nodes_ffhh/nodes.json', 'ffhh_stats')
  17. if 'ffhh_rueckspiegel' in bot.memory and bot.memory['ffhh_rueckspiegel'] == True:
  18. return
  19. stats = bot.memory['ffpb_stats'] if 'ffpb_stats' in bot.memory else None
  20. hamburg_data = bot.memory['ffhh_stats'] if 'ffhh_stats' in bot.memory else None
  21. if not (stats is None or hamburg_data is None):
  22. if hamburg_data['nodes_active'] < stats['nodes_active']:
  23. print('HAMBURG überholt: {0}<{1}'.format(hamburg_data['nodes_active'], stats['nodes_active']))
  24. bot.memory['ffhh_rueckspiegel'] = True
  25. action_msg = u'schaut in den Rückspiegel und erblickt HAMBURG!'
  26. action_target = bot.config.ffpb.msg_target
  27. if not bot.config.ffpb.msg_target_public is None: action_target = bot.config.ffpb.msg_target_public
  28. bot.msg(action_target, '\x01ACTION %s\x01' % action_msg)
  29. @willie.module.commands('hamburg')
  30. def ffpb_hamburg(bot, trigger):
  31. hamburg_data = bot.memory['ffhh_stats'] if 'ffhh_stats' in bot.memory else None
  32. if hamburg_data is None:
  33. bot.say('Hamburg, was ist schon Hamburg ... zumindest habe ich gerade keine Daten.')
  34. return
  35. stats = bot.memory['ffpb_stats'] if 'ffpb_stats' in bot.memory else None
  36. if stats is None:
  37. bot.say('Bitte später nochmal fragen :)')
  38. return
  39. diff_nodes = hamburg_data['nodes_active'] - stats['nodes_active']
  40. diff_clients = hamburg_data['clients'] - stats['clients']
  41. 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))