Browse Source

ffpb: extract fetching of stats out of ffpb_get_stats()

Helge Jung 9 years ago
parent
commit
3abb28cab7
1 changed files with 12 additions and 6 deletions
  1. 12 6
      modules/ffpb.py

+ 12 - 6
modules/ffpb.py

@@ -388,9 +388,8 @@ def ffpb_updatepeers(bot):
 
 		bot.msg(bot.config.ffpb.msg_target, response)
 
-@willie.module.interval(15)
-def ffpb_get_stats(bot):
-	response = urllib2.urlopen('http://map.paderborn.freifunk.net/nodes.json')
+def ffpb_fetch_stats(bot, url, memoryid):
+	response = urllib2.urlopen(url)
 
 	data = json.load(response)
 	nodes_active = 0
@@ -409,13 +408,20 @@ def ffpb_get_stats(bot):
 		if link['type'] == 'client':
 			clients_count += 1
 
-	if not 'ffpb_stats' in bot.memory:
-		bot.memory['ffpb_stats'] = { }
-	stats = bot.memory['ffpb_stats']
+	if not memoryid in bot.memory:
+		bot.memory[memoryid] = { }
+	stats = bot.memory[memoryid]
+	stats["fetchtime"] = time.time()
 	stats["nodes_active"] = nodes_active
 	stats["nodes_total"] = nodes_total
 	stats["clients"] = clients_count
 
+	return (nodes_active, nodes_total, clients_count)
+
+@willie.module.interval(15)
+def ffpb_get_stats(bot):
+	(nodes_active, nodes_total, clients_count) = ffpb_fetch_stats(bot, 'http://map.paderborn.freifunk.net/nodes.json', 'ffpb_stats')
+	
 	highscore_changed = False
 	if nodes_active > highscores['nodes']:
 		highscores['nodes'] = nodes_active