Mercurial > code > home > repos > gcalendarwatch
changeset 43:b5d3d9a8c83d
new graph of just the events happening now
author | drewp@bigasterisk.com |
---|---|
date | Mon, 19 Feb 2024 13:53:46 -0800 |
parents | 7d9609edcf9c |
children | 1d9c4487f21a |
files | gcalendarwatch.py graphconvert.py |
diffstat | 2 files changed, 14 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/gcalendarwatch.py Sun Feb 18 12:34:53 2024 -0800 +++ b/gcalendarwatch.py Mon Feb 19 13:53:46 2024 -0800 @@ -27,7 +27,7 @@ from patchablegraph import PatchableGraph from patchablegraph.handler import GraphEvents, StaticGraph from pymongo import MongoClient -from rdflib import RDF, Graph, Namespace, URIRef +from rdflib import RDF, ConjunctiveGraph, Graph, Namespace, URIRef from starlette.applications import Starlette from starlette.requests import Request from starlette.responses import HTMLResponse, JSONResponse, PlainTextResponse, Response @@ -205,9 +205,16 @@ return PlainTextResponse(msg) +def updateCurrentEvents(conf: Conf, currentEventsGraph: PatchableGraph, collection: pymongo.collection.Collection, first_run: bool): + now = datetime.datetime.now(tzlocal()) + events = list(collection.find({"startTime": {"$lte": now}, "endTime": {"$gte": now}})) + currentEventsGraph.setToGraph(asGraph(conf, cals=[], events=events, extraClasses=[EV['CurrentEvent']])) + + def main(): agendaGraph = PatchableGraph() # next few days countdownGraph = PatchableGraph() # next n of starred events + currentEventsGraph = PatchableGraph() # events happening now conf = cast(Conf, json.load(open("gcalendarwatch.conf"))) m = conf['mongo'] mongoOut = MongoClient(m['host'], m['port'], tz_aware=True)[m['database']][m['collection']] @@ -218,6 +225,7 @@ sync.updateGraphs(read.getEvents(s, e)) loop = background_loop.loop_forever(functools.partial(update, sync=sync), conf['minutes_between_polls'] * 60) + background_loop.loop_forever(functools.partial(updateCurrentEvents, conf, currentEventsGraph, mongoOut), 5, metric_prefix="current_events") def getRoot(request: Request) -> HTMLResponse: return HTMLResponse(content=open("index.html").read().replace("MSG", statusMsg(conf, loop))) @@ -229,6 +237,8 @@ Route('/graph/calendar/upcoming/events', GraphEvents(agendaGraph)), Route('/graph/calendar/countdown', StaticGraph(countdownGraph)), Route('/graph/calendar/countdown/events', GraphEvents(countdownGraph)), + Route('/graph/currentEvents', StaticGraph(currentEventsGraph)), + Route('/graph/currentEvents/events', GraphEvents(currentEventsGraph)), Route('/countdowns.json', functools.partial(Countdowns, countdownGraph)), Route('/events', functools.partial(EventsPage, conf, read)), Route('/pollNow', functools.partial(PollNow, loop), methods=['POST'])
--- a/graphconvert.py Sun Feb 18 12:34:53 2024 -0800 +++ b/graphconvert.py Mon Feb 19 13:53:46 2024 -0800 @@ -18,7 +18,9 @@ graph.add((feed, EV['description'], Literal(doc['description'].strip()), ctx)) for ev in events: - uri = URIRef(ev['uri']) + uri = URIRef(ev.get('uri', ev.get('_id'))) + if uri is None: + raise ValueError(f"{ev=} had no event uri") def add(p: URIRef, o: URIRef|Literal): return graph.add((uri, p, o, ctx))