ffpb_hamburg.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. @willie.module.commands('hamburg')
  18. def ffpb_hamburg(bot, trigger):
  19. hamburg_data = bot.memory['ffhh_stats'] if 'ffhh_stats' in bot.memory else None
  20. if hamburg_data is None:
  21. bot.say('Hamburg, was ist schon Hamburg ... zumindest habe ich gerade keine Daten.')
  22. return
  23. stats = bot.memory['ffpb_stats'] if 'ffpb_stats' in bot.memory else None
  24. if stats is None:
  25. bot.say('Bitte später nochmal fragen :)')
  26. return
  27. diff_nodes = hamburg_data['nodes_active'] - stats['nodes_active']
  28. diff_clients = hamburg_data['clients'] - stats['clients']
  29. 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'])))