From af85c6144b7a10707239205c1c20e560ad15ac41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=20St=C3=B6cker?= Date: Fri, 5 Aug 2016 12:59:13 +0200 Subject: [PATCH 1/2] only change lastchange timestamp if the state has changed --- lastState.txt | 1 + state.py | 38 ++++++++++++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 lastState.txt diff --git a/lastState.txt b/lastState.txt new file mode 100644 index 0000000..2e2e43a --- /dev/null +++ b/lastState.txt @@ -0,0 +1 @@ +0 1470352249 diff --git a/state.py b/state.py index 7ce2d6e..d9e3541 100644 --- a/state.py +++ b/state.py @@ -7,6 +7,7 @@ import logging fileName = "json" url = "http://status.krautspace.de/status/button/" +laststateFile = 'lastState.txt' data = None # Raum Status abrufen @@ -15,7 +16,7 @@ try: except: logging.exception("urllib2") else: - # Status lessen + # Status lesen data = response.read(1) # Data validieren if len(data) != 1 or data not in ("0", "1"): @@ -33,19 +34,40 @@ except: # Bereich in dem der Status steht state = raw["state"] -# letzte Verarbeitungszeit setzen -state["lastchange"] = int(time.time()) + +try: + fp = file(laststateFile) + lastState, oldTimestamp = fp.readline().split() + fp.close() +except: + logging.exception("file") + exit(1) + # Status setzen if data: - if data == "0": - state["open"] = False - state["message"] = "no human being on location" + if lastState != data: + currentTimestamp = int(time.time()) + if data == "0": + state["lastchange"] = currentTimestamp + state["open"] = False + state["message"] = "no human being on location" + else: + state["lastchange"] = currentTimestamp + state["open"] = True + state["message"] = "open for public" + try: + fp = open( laststateFile, 'w' ) + fp.write(data + ' ' + str(currentTimestamp)) + fp.close() + except: + logging.exception("file") + exit(1) else: - state["open"] = True - state["message"] = "open for public" + state["lastchange"] = oldTimestamp else: state["open"] = None state["message"] = "open for public" + state["lastchange"] = oldTimestamp # JSON Decodieren und ausgeben print json.dumps(raw) -- 2.39.5 From 2108f3e3432dd9e100af34f41986b47c3d229357 Mon Sep 17 00:00:00 2001 From: Jens Kubieziel Date: Fri, 13 Jan 2017 15:55:29 +0000 Subject: [PATCH 2/2] URLs angepasst Alle URLs haben jetzt kraut.space als Basis. --- json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/json b/json index b7beb78..02aeb34 100644 --- a/json +++ b/json @@ -5,19 +5,19 @@ "email" ], "contact": { - "ml": "hackspace-jena@list.lstsrv.org", + "ml": "hackspace-jena@lstsrv.org", "twitter": "@HackspaceJena", "identica": "krautspace@quitter.se", - "email": "office@krautspace.de", - "jabber": "krautchan@chat.krautspace.de" + "email": "office@kraut.space", + "jabber": "krautchan@chat.kraut.space" }, "state": { "lastchange": 0, "open": null, "message": "open for public", "icon": { - "open": "https://status.krautspace.de/images/krautspace_pixelicon_open.png", - "closed": "https://status.krautspace.de/images/krautspace_pixelicon_closed.png" + "open": "https://status.kraut.space/images/krautspace_pixelicon_open.png", + "closed": "https://status.kraut.space/images/krautspace_pixelicon_closed.png" } }, "api": "0.13", @@ -26,7 +26,7 @@ "lon": 11.5824294, "address": "Krautgasse 26, 07743 Jena, Germany" }, - "logo": "https://status.krautspace.de/images/krautspace_pixelbanner.png", + "logo": "https://status.kraut.space/images/krautspace_pixelbanner.png", "feeds": { "wiki": { "url": "https://kraut.space/feed.php", -- 2.39.5