Mercurial > code > home > repos > gcalendarwatch
annotate graphconvert.py @ 36:cb990883e52f
deployment; dep updates
author | drewp@bigasterisk.com |
---|---|
date | Sun, 12 Nov 2023 23:19:23 -0800 |
parents | e2209226b001 |
children | 7d9609edcf9c |
rev | line source |
---|---|
28
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
1 from rdflib import RDF, ConjunctiveGraph, Literal, Namespace, URIRef |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
2 |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
3 EV = Namespace("http://bigasterisk.com/event#") |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
4 |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
5 |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
6 def asGraph(events, extraClasses=[], ctx=EV['gcalendar']): |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
7 graph = ConjunctiveGraph() |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
8 graph.namespace_manager.bind('ev', EV) |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
9 for ev in events: |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
10 uri = URIRef(ev['uri']) |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
11 |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
12 def add(p, o): |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
13 return graph.add((uri, p, o, ctx)) |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
14 |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
15 add(RDF.type, EV['Event']) |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
16 for cls in extraClasses: |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
17 add(RDF.type, cls) |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
18 add(EV['title'], Literal(ev['title'])) |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
19 add(EV['start'], Literal(ev['start'])) |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
20 add(EV['startDate'], Literal(ev['startDate'])) |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
21 add(EV['end'], Literal(ev['end'])) |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
22 add(EV['feed'], URIRef(ev['feed'])) |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
23 # graph.add((feed, RDFS.label, Literal(ev['feedTitle']))) |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
24 if 'htmlLink' in ev: |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
25 add(EV['htmlLink'], URIRef(ev['htmlLink'])) |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
26 return graph |