Mercurial > code > home > repos > homeauto
annotate service/xidle/xidle.py @ 1020:5a5badf59503
ipv6 support
Ignore-this: b6fe9c1fe232302cdd1b6469cbc8ac24
darcs-hash:a2a978a5dba938db33107c8928b03680123d4baf
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Sun, 03 Jan 2016 02:27:37 -0800 |
parents | 16b8c4f36f31 |
children | 105969d248d6 |
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 | |
1020 | 46 run(host="[::]", server='gunicorn', port=9107, quiet=True) |
858 | 47 |