-
Notifications
You must be signed in to change notification settings - Fork 23
/
ical.py
42 lines (33 loc) · 1.1 KB
/
ical.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
import asyncio
import os
from ics import Calendar, Event
from config import password, username
from spond import spond
if not os.path.exists("./exports"):
os.makedirs("./exports")
ics_file = os.path.join("./exports", "spond.ics")
async def main():
s = spond.Spond(username=username, password=password)
c = Calendar()
c.method = "PUBLISH"
events = await s.get_events()
for event in events:
e = Event()
e.uid = event["id"]
e.name = event["heading"]
e.begin = event["startTimestamp"]
e.end = event["endTimestamp"]
e.sequence = event["updated"]
e.description = event.get("description")
if "cancelled" in event and event["cancelled"]:
e.status = "Cancelled"
if "location" in event:
e.location = f'{event["location"].get("feature")}, {event["location"].get("address")}'
c.events.add(e)
with open(ics_file, "w") as out_file:
out_file.writelines(c)
await s.clientsession.close()
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
asyncio.run(main())