Mercurial > code > home > repos > homeauto
annotate service/reasoning/rdflibtrig.py @ 1052:2434e88d8bb0
add bed buttons
Ignore-this: 912a92f7a8e173fe64aa4c1df9ef7dba
darcs-hash:2e4031a9cacedb28f57c36708d69d6ec3610ef9d
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Mon, 08 Feb 2016 23:48:29 -0800 |
parents | a328cc370b22 |
children | e5c27d2f11ab |
rev | line source |
---|---|
1045
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
1040
diff
changeset
|
1 import time |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
1040
diff
changeset
|
2 import requests |
1040 | 3 from rdflib import ConjunctiveGraph |
919
6ee2a90fc816
bugs in async http client. move trig helpers to rdflibtrig, which can work with rdflib 4
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
4 |
934
3bb18b7d21df
reasoning actions: generalize them a bit but then add a bunch of special cases for mpd for now
drewp <drewp@bigasterisk.com>
parents:
923
diff
changeset
|
5 def addTrig(graph, url, timeout=2): |
919
6ee2a90fc816
bugs in async http client. move trig helpers to rdflibtrig, which can work with rdflib 4
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
6 t1 = time.time() |
1045
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
1040
diff
changeset
|
7 response = requests.get(url, stream=True, timeout=timeout) |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
1040
diff
changeset
|
8 if response.status_code != 200: |
923
4ae49c6adecb
errors and logging in reasoning
drewp <drewp@bigasterisk.com>
parents:
919
diff
changeset
|
9 raise ValueError("status %s from %s" % (response.status, url)) |
1045
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
1040
diff
changeset
|
10 g = ConjunctiveGraph() |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
1040
diff
changeset
|
11 g.parse(response.raw, format='trig') |
919
6ee2a90fc816
bugs in async http client. move trig helpers to rdflibtrig, which can work with rdflib 4
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
12 fetchTime = time.time() - t1 |
1040 | 13 graph.addN(g.quads()) |
919
6ee2a90fc816
bugs in async http client. move trig helpers to rdflibtrig, which can work with rdflib 4
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
14 return fetchTime |