-
Notifications
You must be signed in to change notification settings - Fork 5
/
node_stats.py
executable file
·44 lines (40 loc) · 1.35 KB
/
node_stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/python
# -*- coding: utf-8 -
#Imports:
import urllib, json, datetime, time
def getFile(nodesFile):
printStatus = False
if nodesFile.startswith('https://') or nodesFile.startswith('http://'):
if printStatus:
print "Download node.json from URL: " + nodesFile
response = urllib.urlopen(nodesFile)
else:
if printStatus:
print "Open node.json file: " + nodesFile
response = open(nodesFile)
return json.loads(response.read())
def getGeoNodes(data, lastSeenHours = False, isOnline = True):
nodes = []
count = 0
lastDay = datetime.datetime.today() - datetime.timedelta(hours = lastSeenHours)
for node in data['nodes'].itervalues():
knoten = node['nodeinfo']
if isOnline:
if lastSeenHours != False and lastSeenHours != 0:
if 'lastseen' in node:
nodeLastSeen = datetime.datetime.strptime(node['lastseen'],'%Y-%m-%dT%H:%M:%S')
if nodeLastSeen >= lastDay or node['flags']['online']:
count += 1
else:
if node['flags']['online']:
count += 1
else:
count += 1
return count
nodefile = 'https://service.freifunk-muensterland.de/maps/data/nodes.json'
nodesData = getFile(nodefile)
print 'offset_days;nodes_count'
#for i in range(0,3648,24):
for i in range(0,4600,24):
print str(i/24) + ';' + str(getGeoNodes(nodesData, i))
#print 'Nodes online last ' + str(i/24) + ' days: ' + str(getGeoNodes(nodesData, i))