From 3b1ab2aff54c9bf9bc8f400b5a7d7b6c33f98af8 Mon Sep 17 00:00:00 2001 From: cyfraeviolae Date: Wed, 3 Apr 2024 04:24:22 -0400 Subject: cal --- app.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/app.py b/app.py index d22c28d..798d4fd 100644 --- a/app.py +++ b/app.py @@ -64,14 +64,23 @@ class Event(Base): return json.loads(self.invites) def to_ics(self): - c = ics.Calendar() - e = ics.Event() - e.name = self.title - e.begin = self.time - e.location = self.location - e.description = self.description - c.events.add(e) - return c + fmt = "%Y%m%dT%H%M%SZ" + start = self.time.strftime(fmt) + now = datetime.datetime.now().strftime(fmt) + return f''' +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:custom +BEGIN:VEVENT +DESCRIPTION:{self.description} +LOCATION:{self.location} +DTSTART:{start} +DTSTAMP:{now} +SUMMARY:{self.title} +UID:{self.iden} +END:VEVENT +END:VCALENDAR + ''' @asynccontextmanager async def db_connection(app: Litestar) -> AsyncGenerator[None, None]: @@ -128,7 +137,7 @@ async def calendar(state: State, iden: str) -> ASGIStreamingResponse: result = await session.execute(query) event = result.scalar_one() ics = event.to_ics() - f = io.StringIO(ics.serialize()) + f = io.StringIO(ics) return ASGIStreamingResponse(iterator=f, media_type='text/plain', headers={ 'Content-Disposition': 'attachment; filename=event.ics', }) -- cgit v1.2.3