summaryrefslogtreecommitdiff
path: root/subcan.py
diff options
context:
space:
mode:
authorChristian Franke <nobody@nowhere.ws>2013-03-17 12:42:09 +0100
committerChristian Franke <nobody@nowhere.ws>2013-03-17 12:47:40 +0100
commit625fc3e4fd50451b950c3d1e2bf2356fb74dcefa (patch)
treed10c9a187b505b881c3bc29c18dabbcf6bf5e8f7 /subcan.py
parent76c0532b5638eda76e71a748832290adb985f21a (diff)
Add the other scripts (funny code is funny)
Diffstat (limited to 'subcan.py')
-rw-r--r--subcan.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/subcan.py b/subcan.py
new file mode 100644
index 0000000..40d476d
--- /dev/null
+++ b/subcan.py
@@ -0,0 +1,50 @@
+import json
+import sys
+from lxml import etree
+from time import time, sleep
+
+def run():
+ doc = etree.parse('subcan.svg')
+ data = json.loads(file('/home/services/http/subcan.json').read())
+
+ for i in ['door.left', 'door.right', 'door.lock']:
+ cond = '%s=%s' % (i, data[i]['text'])
+ print cond
+ elems = doc.xpath('//svg:g[@inkscape:label="%s"]' % (cond,),
+ namespaces = {
+ 'svg': 'http://www.w3.org/2000/svg',
+ 'inkscape': 'http://www.inkscape.org/namespaces/inkscape',
+ })
+ for e in elems:
+ e.set('style', 'display:inline')
+
+ for i in data.keys():
+ if not i.startswith('dali.'):
+ continue
+ for j in ['set', 'actual']:
+ #for i in [('dali.lounge', 'set'), ('dali.lounge', 'actual')]:
+ elems = doc.xpath('//svg:text[@id="%s_%s"]/svg:tspan' % (i, j),
+ namespaces = {
+ 'svg': 'http://www.w3.org/2000/svg',
+ })
+ print 'elems for %s_%s: %d' % (i, j, len(elems))
+ for e in elems:
+ try:
+ text = data[i][j]
+ if data[i][j + '_ts'] > time() - 300.:
+ text = u'%d%%' % (text / 254. * 100.)
+ else:
+ text = u'<?>'
+ e.text = text
+ except KeyError:
+ print 'error processing \'%s_%s\'' % (i, j)
+ e.text = u'<?>'
+
+ file('/home/services/http/subcan.svg', 'w').write(etree.tostring(doc))
+
+while True:
+ try:
+ run()
+ except Exception:
+ sys.excepthook(*sys.exc_info())
+ sleep(10.)