Mercurial > code > home > repos > homeauto
annotate service/xidle/xidle.py @ 963:2decd45addf4
notes on pins
Ignore-this: 1fced0c832715c5fbd16011563e7120a
darcs-hash:20150120053811-312f9-cbcd7801cd4a454a3ae4a05c5534cfb0a9cbafb8
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Mon, 19 Jan 2015 21:38:11 -0800 |
parents | 16b8c4f36f31 |
children | 1e94d074f642 |
rev | line source |
---|---|
858 | 1 #!bin/python |
874
16b8c4f36f31
add idleTimeMinutes to rdf graph
drewp <drewp@bigasterisk.com>
parents:
858
diff
changeset
|
2 from __future__ import division |
858 | 3 """ |
4 X server idle time is now available over http! | |
5 """ | |
6 | |
7 from bottle import run, get, put, request, response | |
8 import subprocess, sys, socket | |
9 from rdflib import Namespace, URIRef, Literal | |
10 | |
11 # from http://bebop.bigasterisk.com/python/ | |
12 import xss | |
13 # another option: http://thp.io/2007/09/x11-idle-time-and-focused-window-in.html | |
14 | |
15 DEV = Namespace("http://projects.bigasterisk.com/device/") | |
16 ROOM = Namespace("http://projects.bigasterisk.com/room/") | |
17 | |
18 sys.path.append("/my/site/magma") | |
19 from stategraph import StateGraph | |
20 | |
21 host = socket.gethostname() | |
22 | |
23 @get("/") | |
24 def index(): | |
25 xss.get_info() # fail if we can't get the display or something | |
26 return ''' | |
27 Get the <a href="idle">X idle time</a> on %s. | |
28 <a href="graph">rdf graph</a> available.''' % host | |
29 | |
30 @get("/idle") | |
31 def monitor(): | |
32 return {"idleMs" : xss.get_info().idle} | |
33 | |
34 @get("/graph") | |
35 def graph(): | |
36 g = StateGraph(ctx=DEV['xidle/%s' % host]) | |
874
16b8c4f36f31
add idleTimeMinutes to rdf graph
drewp <drewp@bigasterisk.com>
parents:
858
diff
changeset
|
37 |
16b8c4f36f31
add idleTimeMinutes to rdf graph
drewp <drewp@bigasterisk.com>
parents:
858
diff
changeset
|
38 ms = xss.get_info().idle |
16b8c4f36f31
add idleTimeMinutes to rdf graph
drewp <drewp@bigasterisk.com>
parents:
858
diff
changeset
|
39 subj = URIRef("http://bigasterisk.com/host/%s/xidle" % host) |
16b8c4f36f31
add idleTimeMinutes to rdf graph
drewp <drewp@bigasterisk.com>
parents:
858
diff
changeset
|
40 g.add((subj, ROOM['idleTimeMs'], Literal(ms))) |
16b8c4f36f31
add idleTimeMinutes to rdf graph
drewp <drewp@bigasterisk.com>
parents:
858
diff
changeset
|
41 g.add((subj, ROOM['idleTimeMinutes'], Literal(ms / 1000 / 60))) |
858 | 42 |
43 response.set_header('Content-type', 'application/x-trig') | |
44 return g.asTrig() | |
45 | |
46 run(host="0.0.0.0", server='gunicorn', port=9107, quiet=True) | |
47 |