Mercurial > code > home > repos > homeauto
annotate service/reasoning/rdflibtrig.py @ 1754:92999dfbf321 default tip
add shelly support
author | drewp@bigasterisk.com |
---|---|
date | Tue, 04 Jun 2024 13:03:43 -0700 |
parents | 3c18b4b3b72c |
children |
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 |
760 | 14 for name, addr in ipv6Addresses.items(): |
249 | 15 url = url.replace('/' + name + ':', '/[' + addr + ']:') |
16 log.debug(' fetching %r', url) | |
760 | 17 response = yield treq.get(url, headers={'accept': ['application/trig']}, |
18 timeout=timeout) | |
249 | 19 if response.code != 200: |
20 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
|
21 g = ConjunctiveGraph() |
249 | 22 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
|
23 fetchTime = time.time() - t1 |
249 | 24 log.debug(' %r done in %.04f sec', url, fetchTime) |
235 | 25 graph.addN(g.quads()) |
249 | 26 returnValue(fetchTime) |