summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Franke <nobody@nowhere.ws>2012-09-17 19:09:42 +0200
committerChristian Franke <nobody@nowhere.ws>2012-09-17 19:09:42 +0200
commit647dc1883be469b0d474c3a9528ce3a01595b377 (patch)
tree66df696c2ab90d014fa8544539d7dba3a0364141
parent13026ffc6bb3b697f2e02b423597159d8e3a42ff (diff)
Add spaceapi script
-rw-r--r--scripts/sub_api.py30
-rw-r--r--template/template.spaceapi.json23
2 files changed, 53 insertions, 0 deletions
diff --git a/scripts/sub_api.py b/scripts/sub_api.py
new file mode 100644
index 0000000..fb847ed
--- /dev/null
+++ b/scripts/sub_api.py
@@ -0,0 +1,30 @@
+#!/usr/bin/python
+
+import json
+import urllib
+
+import os.path
+
+base_path = os.path.realpath(os.path.dirname(__file__))
+base_path = os.path.join(base_path, '..')
+
+#declarations
+
+input_url = "http://taifun.local.sublab.org/subcan.json"
+json_template = os.path.join(base_path, "template", "template.spaceapi.json")
+output_file = os.path.join(base_path, "public", "sublab_status.json")
+status_dict = { "open" : True , "closed" : False }
+
+#read door status
+status_json = json.load(urllib.urlopen(input_url))
+door_status = status_json["door.lock"]["text"]
+
+#fill status in template
+sublab_status = json.load(open(json_template))
+sublab_status["open"] = status_dict[door_status]
+
+#atomically place new status
+new_output_file = output_file + '.new'
+with open(new_output_file, "w") as status_file:
+ status_file.write(json.dumps(sublab_status, sort_keys=True, indent=4))
+os.rename(new_output_file, output_file)
diff --git a/template/template.spaceapi.json b/template/template.spaceapi.json
new file mode 100644
index 0000000..527b27e
--- /dev/null
+++ b/template/template.spaceapi.json
@@ -0,0 +1,23 @@
+{
+ "api":"0.12",
+ "space":"sublab",
+ "logo":"http:\/\/sublab.org\/img\/sublab_logo_large.png",
+ "icon":{
+ "open":"http:\/\/sublab.org\/img/open.png",
+ "closed":"https:\/\/sublab.org\/img\/closed.png"
+ },
+ "url":"http:\/\/sublab.org",
+ "address":"Karl-Heine-Strasse 93, 04229 Leipzig, Germany",
+ "contact":{
+ "phone":"+4934139299356",
+ "twitter":"@sublab",
+ "ml":"sublab-discuss@lists.subsignal.org",
+ "irc":"irc:\/\/hackint.org\/#sublab",
+ "jabber":"xmpp:#sublab@irc.hackint.org",
+ "email":"kontakt@sublab.org"
+ },
+ "lat":12.331125,
+ "lon":51.330398,
+ "cam":["http:\/\/sublab.org\/img\/rack.webcam.jpg"],
+ "open":false
+}