Mercurial > code > home > repos > homeauto
annotate service/reasoning/rdflibtrig.py @ 722:a93fbf0d0daa
dep updates; graph url renames; and other build updates
Ignore-this: 4603ef3d8db650a13e543dad8580ade8
author | drewp@bigasterisk.com |
---|---|
date | Wed, 05 Feb 2020 00:23:06 -0800 |
parents | e5c27d2f11ab |
children | 3c18b4b3b72c |
rev | line source |
---|---|
249 | 1 import time, logging |
235 | 2 from rdflib import ConjunctiveGraph |
249 | 3 from rdflib.parser import StringInputSource |
4 import treq | |
5 from twisted.internet.defer import inlineCallbacks, returnValue | |
6 log = logging.getLogger('fetch') | |
7 | |
8 from private_ipv6_addresses import ipv6Addresses | |
9 | |
10 @inlineCallbacks | |
129
745eff67ad40
reasoning actions: generalize them a bit but then add a bunch of special cases for mpd for now
drewp@bigasterisk.com
parents:
118
diff
changeset
|
11 def addTrig(graph, url, timeout=2): |
114
4cd065b97fa1
bugs in async http client. move trig helpers to rdflibtrig, which can work with rdflib 4
drewp@bigasterisk.com
parents:
diff
changeset
|
12 t1 = time.time() |
249 | 13 # workaround for some reason my ipv6 names don't resolve |
14 for name, addr in ipv6Addresses.iteritems(): | |
15 url = url.replace('/' + name + ':', '/[' + addr + ']:') | |
16 log.debug(' fetching %r', url) | |
17 response = yield treq.get(url, headers={'accept': ['application/trig']}, timeout=timeout) | |
18 if response.code != 200: | |
19 raise ValueError("status %s from %s" % (response.code, url)) | |
240
0c306e76d8c5
ipv6 fetch support. refactor Actions to new class and file
drewp@bigasterisk.com
parents:
235
diff
changeset
|
20 g = ConjunctiveGraph() |
249 | 21 g.parse(StringInputSource((yield response.content())), format='trig') |
114
4cd065b97fa1
bugs in async http client. move trig helpers to rdflibtrig, which can work with rdflib 4
drewp@bigasterisk.com
parents:
diff
changeset
|
22 fetchTime = time.time() - t1 |
249 | 23 log.debug(' %r done in %.04f sec', url, fetchTime) |
235 | 24 graph.addN(g.quads()) |
249 | 25 returnValue(fetchTime) |