-
Notifications
You must be signed in to change notification settings - Fork 4
/
cal.py
59 lines (47 loc) · 1.14 KB
/
cal.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from ics import Calendar, Event
from datetime import date, timedelta
from db import fetchall_dict
from rich import print
from flag import flag
c = Calendar()
def add_allday_event(c, event_start, event_name, event_description):
e = Event(
event_name,
description=event_description,
begin=event_start.isoformat(),
end=(event_start + timedelta(days=1)).isoformat(),
transparent=True,
)
e.make_all_day()
c.events.add(e)
cities = fetchall_dict(
"""
select
u
, c.n
, concat_ws(', ', c.s,c.c) s
, v.video
from cities c
JOIN videos v ON v.id = c.id
order by (rank < 3500 and c.id < 3500) DESC
, ROW_NUMBER() OVER ( PARTITION BY u ) -- prefer to show many countries
, random()
--limit 2
"""
)
START_DATE = date.today()
for city in cities:
print(city)
add_allday_event(
c,
event_start=START_DATE,
event_name=flag(city["u"]) + " " + city["n"],
event_description=f"""{city["n"]} welcomes you !
{city["video"]}
{city["s"]}
""",
)
START_DATE += timedelta(2)
c.events
with open("my.ics", "w") as my_file:
my_file.writelines(c)