Mercurial > code > home > repos > gcalendarwatch
diff graphconvert.py @ 42:7d9609edcf9c
track calendar feed summary/description text and emit them in graphs
author | drewp@bigasterisk.com |
---|---|
date | Sun, 18 Feb 2024 12:34:53 -0800 |
parents | e2209226b001 |
children | b5d3d9a8c83d |
line wrap: on
line diff
--- a/graphconvert.py Sun Feb 18 12:33:52 2024 -0800 +++ b/graphconvert.py Sun Feb 18 12:34:53 2024 -0800 @@ -1,15 +1,26 @@ -from rdflib import RDF, ConjunctiveGraph, Literal, Namespace, URIRef +from localtypes import Conf, feedFromCalId +from rdflib import RDF, RDFS, ConjunctiveGraph, Literal, Namespace, URIRef EV = Namespace("http://bigasterisk.com/event#") -def asGraph(events, extraClasses=[], ctx=EV['gcalendar']): +def asGraph(conf: Conf, cals, events, extraClasses=[], ctxUri:URIRef=EV['gcalendar']): + ctx = ConjunctiveGraph(identifier=ctxUri) graph = ConjunctiveGraph() graph.namespace_manager.bind('ev', EV) + + for doc in cals: + feed = URIRef(feedFromCalId(conf, doc['_id'])) + graph.add((feed, RDF.type, EV['CalendarFeed'], ctx)) + if doc['summary']: + graph.add((feed, RDFS.label, Literal(doc['summary'].strip()), ctx)) + if doc['description']: + graph.add((feed, EV['description'], Literal(doc['description'].strip()), ctx)) + for ev in events: uri = URIRef(ev['uri']) - def add(p, o): + def add(p: URIRef, o: URIRef|Literal): return graph.add((uri, p, o, ctx)) add(RDF.type, EV['Event'])