2015-12-01 21:44:45 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#Bibliotheken importieren
|
|
|
|
import time
|
|
|
|
import datetime
|
|
|
|
import json
|
2017-06-16 23:35:42 +02:00
|
|
|
import urllib2
|
2015-12-01 21:44:45 +01:00
|
|
|
|
|
|
|
#Datei oeffnen
|
2017-06-16 23:35:42 +02:00
|
|
|
Datei = urllib2.urlopen('https://map.hamburg.freifunk.net/nodes.json')
|
|
|
|
Datei_Sued = urllib2.urlopen('https://map.hamburg.freifunk.net/hhsued/mv1/nodes.json')
|
2015-12-01 21:44:45 +01:00
|
|
|
|
2017-06-16 23:35:42 +02:00
|
|
|
Text = Datei.read()
|
2017-06-16 23:41:11 +02:00
|
|
|
Knotenzahl = Text.count('"online": true')
|
2017-06-16 23:35:42 +02:00
|
|
|
Text = Datei_Sued.read()
|
2017-06-16 23:41:11 +02:00
|
|
|
Knotenzahl = Knotenzahl + Text.count('"online":true')
|
2015-12-01 21:44:45 +01:00
|
|
|
|
|
|
|
#Zeit holen
|
|
|
|
thetime = datetime.datetime.now().isoformat()
|
|
|
|
|
|
|
|
ffhh = None
|
|
|
|
|
|
|
|
#Freifunk API-Datei einladen und JSON lesen
|
|
|
|
with open('/var/www/meta/ffhh.json', 'r') as fp:
|
|
|
|
ffhh = json.load(fp)
|
|
|
|
|
|
|
|
#Attribute Zeitstempel und Knotenanzahl setzen
|
|
|
|
ffhh['state']['lastchange'] = thetime
|
2017-06-16 23:41:11 +02:00
|
|
|
ffhh['state']['nodes'] = Knotenzahl
|
2015-12-01 21:44:45 +01:00
|
|
|
|
|
|
|
#Freifunk API-Datein mit geaenderten werten schreiben
|
|
|
|
with open('/var/www/meta/ffhh.json', 'w') as fp:
|
|
|
|
json.dump(ffhh, fp, indent=2, separators=(',', ': '))
|