summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xscripts/status_script.py57
-rw-r--r--template/template/template.html12
2 files changed, 69 insertions, 0 deletions
diff --git a/scripts/status_script.py b/scripts/status_script.py
new file mode 100755
index 0000000..1c229e0
--- /dev/null
+++ b/scripts/status_script.py
@@ -0,0 +1,57 @@
+#!/usr/bin/python
+
+import urllib
+import contextlib
+import json
+import time
+import os
+
+class SublabStatus(object):
+ json = None
+ def get_json(self):
+ if self.json is not None:
+ return self.json
+
+ with contextlib.closing(urllib.urlopen('http://taifun.local.sublab.org/subcan.json')) as response:
+ self.json = json.load(response)
+ return self.json
+
+ def door_status(self):
+ self.get_json()
+ door_status = self.json['door.lock']
+
+ if door_status['ts'] + 120 < time.time():
+ return 'unknown'
+
+ if not door_status['value']:
+ return 'open'
+ else:
+ return 'closed'
+
+if __name__ == '__main__':
+ s = SublabStatus()
+ if s.door_status() == 'open':
+ colors = ('#0f0', '#222')
+ elif s.door_status() == 'closed':
+ colors = ('#222', '#f00')
+ else:
+ colors = ('#222', '#222')
+
+ css = '''
+span.sublabopen {
+ color: %s;
+}
+
+
+span.sublabclosed {
+ color: %s;
+}
+''' % colors
+
+ path = os.path.realpath(os.path.dirname(__file__))
+ path = os.path.join(path, '..', 'public', 'css', 'sublab.status.css')
+ path_new = path + '.new'
+
+ with open(path_new, 'w') as css_file:
+ css_file.write(css)
+ os.rename(path_new, path)
diff --git a/template/template/template.html b/template/template/template.html
index 165e578..fe931e9 100644
--- a/template/template/template.html
+++ b/template/template/template.html
@@ -19,6 +19,7 @@
<link rel="stylesheet" href="css/taifun.status.css" type="text/css">
<link rel="stylesheet" href="css/trieste.status.css" type="text/css">
<link rel="stylesheet" href="css/nautilus.status.css" type="text/css">
+ <link rel="stylesheet" href="css/sublab.status.css" type="text/css">
<link rel="shortcut icon" href="img/favicon.png">
</head>
@@ -89,6 +90,17 @@
<table>
<tr>
<td class="status">
+ sublab:
+ </td>
+ <td class="statusinfo">
+ <span class="sublabopen">Open</span>&nbsp;&nbsp;<span class="sublabclosed">Closed</span>
+ </td>
+ </tr>
+ </table>
+ <hr>
+ <table>
+ <tr>
+ <td class="status">
Taifun:
</td>
<td class="statusinfo">