forked from freifunkMUC/freifunk.net-API
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnode_stats.py
More file actions
31 lines (22 loc) · 765 Bytes
/
node_stats.py
File metadata and controls
31 lines (22 loc) · 765 Bytes
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
from datetime import datetime
from requests import get as rget
NODESJSON = 'https://map.tecff.de/yanic/nodes.json'
def scrape(url):
'''returns remote json'''
try:
return rget(url).json()
except Exception as ex:
print('Error: %s' %(ex))
if __name__ == '__main__':
nodes = scrape(NODESJSON)
if nodes:
online = 0
nonclient = 0
for node in nodes['nodes']:
if node['flags']['online']:
online += 1
if node['flags']['gateway']:
nonclient += 1
now = datetime.now().strftime('%H:%M %d.%m.%Y')
resultmsg = 'Status: online: %d (%d Router, %d Teilnehmer) %s' %(online, nonclient, online-nonclient, now)
print(resultmsg)