view graphconvert.py @ 28:e2209226b001

rewrite with starlette and background_loop
author drewp@bigasterisk.com
date Sun, 24 Jul 2022 00:58:54 -0700
parents
children 7d9609edcf9c
line wrap: on
line source

from rdflib import RDF, ConjunctiveGraph, Literal, Namespace, URIRef

EV = Namespace("http://bigasterisk.com/event#")


def asGraph(events, extraClasses=[], ctx=EV['gcalendar']):
    graph = ConjunctiveGraph()
    graph.namespace_manager.bind('ev', EV)
    for ev in events:
        uri = URIRef(ev['uri'])

        def add(p, o):
            return graph.add((uri, p, o, ctx))

        add(RDF.type, EV['Event'])
        for cls in extraClasses:
            add(RDF.type, cls)
        add(EV['title'], Literal(ev['title']))
        add(EV['start'], Literal(ev['start']))
        add(EV['startDate'], Literal(ev['startDate']))
        add(EV['end'], Literal(ev['end']))
        add(EV['feed'], URIRef(ev['feed']))
        # graph.add((feed, RDFS.label, Literal(ev['feedTitle'])))
        if 'htmlLink' in ev:
            add(EV['htmlLink'], URIRef(ev['htmlLink']))
    return graph