summaryrefslogtreecommitdiff
path: root/app.py
diff options
context:
space:
mode:
authorcyfraeviolae <cyfraeviolae>2024-04-03 04:24:22 -0400
committercyfraeviolae <cyfraeviolae>2024-04-03 04:24:22 -0400
commit3b1ab2aff54c9bf9bc8f400b5a7d7b6c33f98af8 (patch)
treea20031a99b6a46e2f5bfa2fcf040ab59f50cc5f8 /app.py
parentbcc49bc4638cdfddb5e49954b51c98f771cabe82 (diff)
cal
Diffstat (limited to 'app.py')
-rw-r--r--app.py27
1 files 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',
})