日历:从在线日历获取事件

从在线日历获取事件

Outlook 查看日历链接: 设置-日历-共享日历-发布日历,可以看到如下链接:

https://outlook.live.com/owa/calendar/d82e6afe-XXXX-XXXX/cid-YYYY/calendar.ics

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
from ics import Calendar
import requests

# Parse the URL
url = "https://outlook.live.com/owa/calendar/d82e6afe--XXXX-XXXX/cid-YYYY/calendar.ics"
cal = Calendar(requests.get(url).text)


#%%
# Print all the events
events = sorted(cal.events)
for event in events:
print(event.begin , event.name )

#%%
timeline = cal.timeline
for tl in timeline:
print(tl.begin , tl.name )

# %%
# 获取今天及之后的事件
from ics import Calendar
import requests
import arrow

cal = Calendar(requests.get(url).text)

today = arrow.now()
print(today)
today = arrow.now().replace(hour=0, minute=0, second=0, microsecond=0)
print(today)
today = arrow.now().span('day')[0]
print(today)

evts = cal.timeline.start_after(today)

for evt in evts:
print(evt.begin.strftime("%Y-%m-%d %a %H:%M"), evt.name )