diff options
author | cyfraeviolae <cyfraeviolae> | 2024-04-03 04:24:22 -0400 |
---|---|---|
committer | cyfraeviolae <cyfraeviolae> | 2024-04-03 04:24:22 -0400 |
commit | 3b1ab2aff54c9bf9bc8f400b5a7d7b6c33f98af8 (patch) | |
tree | a20031a99b6a46e2f5bfa2fcf040ab59f50cc5f8 | |
parent | bcc49bc4638cdfddb5e49954b51c98f771cabe82 (diff) |
cal
-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', }) |