diff options
-rw-r--r-- | app.py | 27 |
1 files changed, 18 insertions, 9 deletions
@@ -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', }) |