Mercurial > code > home > repos > gcalendarwatch
annotate graphconvert.py @ 91:62caecb41dfd default tip
fix tag
author | drewp@bigasterisk.com |
---|---|
date | Fri, 03 Jan 2025 18:06:13 -0800 |
parents | 5ace21c3de98 |
children |
rev | line source |
---|---|
85
f75b3a109b66
rewrite gcalendarwatch to read from calsync's mongo data only, not google services
drewp@bigasterisk.com
parents:
48
diff
changeset
|
1 from pprint import pformat, pprint |
45
e53a1bc87f99
cleanup and some fixes to starred event graph
drewp@bigasterisk.com
parents:
43
diff
changeset
|
2 from dateutil.tz import tzlocal |
e53a1bc87f99
cleanup and some fixes to starred event graph
drewp@bigasterisk.com
parents:
43
diff
changeset
|
3 from rdflib import RDF, RDFS, ConjunctiveGraph, Literal, Namespace, URIRef |
85
f75b3a109b66
rewrite gcalendarwatch to read from calsync's mongo data only, not google services
drewp@bigasterisk.com
parents:
48
diff
changeset
|
4 import logging |
f75b3a109b66
rewrite gcalendarwatch to read from calsync's mongo data only, not google services
drewp@bigasterisk.com
parents:
48
diff
changeset
|
5 from localtypes import Conf, Record |
45
e53a1bc87f99
cleanup and some fixes to starred event graph
drewp@bigasterisk.com
parents:
43
diff
changeset
|
6 |
85
f75b3a109b66
rewrite gcalendarwatch to read from calsync's mongo data only, not google services
drewp@bigasterisk.com
parents:
48
diff
changeset
|
7 log = logging.getLogger('conv') |
28
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
8 EV = Namespace("http://bigasterisk.com/event#") |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
9 |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
10 |
85
f75b3a109b66
rewrite gcalendarwatch to read from calsync's mongo data only, not google services
drewp@bigasterisk.com
parents:
48
diff
changeset
|
11 def asGraph(conf: Conf, cals: list, events: list[Record], extraClasses=[], ctxUri: URIRef = EV['gcalendar']): |
42
7d9609edcf9c
track calendar feed summary/description text and emit them in graphs
drewp@bigasterisk.com
parents:
28
diff
changeset
|
12 ctx = ConjunctiveGraph(identifier=ctxUri) |
28
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
13 graph = ConjunctiveGraph() |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
14 graph.namespace_manager.bind('ev', EV) |
42
7d9609edcf9c
track calendar feed summary/description text and emit them in graphs
drewp@bigasterisk.com
parents:
28
diff
changeset
|
15 |
7d9609edcf9c
track calendar feed summary/description text and emit them in graphs
drewp@bigasterisk.com
parents:
28
diff
changeset
|
16 for doc in cals: |
85
f75b3a109b66
rewrite gcalendarwatch to read from calsync's mongo data only, not google services
drewp@bigasterisk.com
parents:
48
diff
changeset
|
17 cal = URIRef(doc['_id']) |
f75b3a109b66
rewrite gcalendarwatch to read from calsync's mongo data only, not google services
drewp@bigasterisk.com
parents:
48
diff
changeset
|
18 graph.add((cal, RDF.type, EV['CalendarFeed'], ctx)) |
42
7d9609edcf9c
track calendar feed summary/description text and emit them in graphs
drewp@bigasterisk.com
parents:
28
diff
changeset
|
19 if doc['summary']: |
85
f75b3a109b66
rewrite gcalendarwatch to read from calsync's mongo data only, not google services
drewp@bigasterisk.com
parents:
48
diff
changeset
|
20 graph.add((cal, RDFS.label, Literal(doc['summary'].strip()), ctx)) |
42
7d9609edcf9c
track calendar feed summary/description text and emit them in graphs
drewp@bigasterisk.com
parents:
28
diff
changeset
|
21 if doc['description']: |
85
f75b3a109b66
rewrite gcalendarwatch to read from calsync's mongo data only, not google services
drewp@bigasterisk.com
parents:
48
diff
changeset
|
22 graph.add((cal, EV['description'], Literal(doc['description'].strip()), ctx)) |
42
7d9609edcf9c
track calendar feed summary/description text and emit them in graphs
drewp@bigasterisk.com
parents:
28
diff
changeset
|
23 |
28
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
24 for ev in events: |
85
f75b3a109b66
rewrite gcalendarwatch to read from calsync's mongo data only, not google services
drewp@bigasterisk.com
parents:
48
diff
changeset
|
25 uri = URIRef(ev['_id']) |
f75b3a109b66
rewrite gcalendarwatch to read from calsync's mongo data only, not google services
drewp@bigasterisk.com
parents:
48
diff
changeset
|
26 |
f75b3a109b66
rewrite gcalendarwatch to read from calsync's mongo data only, not google services
drewp@bigasterisk.com
parents:
48
diff
changeset
|
27 graph.add((URIRef(ev['calendarUrl']), EV['event'], uri, ctx)) |
28
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
28 |
45
e53a1bc87f99
cleanup and some fixes to starred event graph
drewp@bigasterisk.com
parents:
43
diff
changeset
|
29 def add(p: URIRef, o: URIRef | Literal): |
28
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
30 return graph.add((uri, p, o, ctx)) |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
31 |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
32 add(RDF.type, EV['Event']) |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
33 for cls in extraClasses: |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
34 add(RDF.type, cls) |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
35 add(EV['title'], Literal(ev['title'])) |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
36 add(EV['start'], Literal(ev['start'])) |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
37 add(EV['startDate'], Literal(ev['startDate'])) |
90 | 38 add(EV['endDate'], Literal(ev['endDate'])) |
28
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
39 add(EV['end'], Literal(ev['end'])) |
85
f75b3a109b66
rewrite gcalendarwatch to read from calsync's mongo data only, not google services
drewp@bigasterisk.com
parents:
48
diff
changeset
|
40 add(EV['feed'], URIRef(ev['calendarUrl'])) |
28
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
41 if 'htmlLink' in ev: |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
42 add(EV['htmlLink'], URIRef(ev['htmlLink'])) |
e2209226b001
rewrite with starlette and background_loop
drewp@bigasterisk.com
parents:
diff
changeset
|
43 return graph |