-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathical.py
53 lines (42 loc) · 1.73 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
43
44
45
46
47
48
49
50
51
52
53
import requests
import re
from datetime import datetime, timedelta
#change with your online ics file
url = 'https://calendar.google.com/calendar/ical/[..]/[..]/basic.ics'
ical_data = requests.get(url).text
event_pattern = re.compile(r'BEGIN:VEVENT(.*?)END:VEVENT', re.DOTALL)
events = event_pattern.findall(ical_data)
today = datetime.now().date() #Date without time
now = datetime.now()
date_time = now.strftime("%d.%m.%Y / %H:%M")
for event in events:
description_match = re.search(r'SUMMARY:(.*?)\n', event)
start_time_match = re.search(r'DTSTART:(.*?)\n', event)
end_time_match = re.search(r'DTEND:(.*?)\n', event)
if description_match:
description = description_match.group(1)
else:
description = 'Kein Titel'
if start_time_match:
start_time_str = start_time_match.group(1)
start_time = datetime.strptime(start_time_str, "%Y%m%dT%H%M%SZ\r").date() #.strftime("%d.%m.%Y / %H:%M")
if start_time == today:
start_time = datetime.strptime(start_time_str, "%Y%m%dT%H%M%SZ\r").strftime("%d.%m.%Y / %H:%M")
else:
continue
else:
start_time = 'Kein Anfangszeitpunkt vorhanden'
if end_time_match:
end_time_str = end_time_match.group(1)
end_time = datetime.strptime(end_time_str, "%Y%m%dT%H%M%SZ\r").date() #strftime("%d.%m.%Y / %H:%M")
if end_time == today:
end_time = datetime.strptime(end_time_str, "%Y%m%dT%H%M%SZ\r").strftime("%d.%m.%Y / %H:%M")
else:
continue #end_time = 'Kein Anfangszeitpunkt vorhanden'
else:
end_time = 'Kein Endzeitpunkt vorhanden'
print("\n")
print("Termin:", description)
print("Start:", start_time)
print("Ende :", end_time)
print("\n")