-
Notifications
You must be signed in to change notification settings - Fork 0
/
calendarEdit.py
62 lines (50 loc) · 1.58 KB
/
calendarEdit.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
60
61
62
from ics import Calendar, Event
import arrow
from pathlib import Path
calendarPath = "sallesMQ.ics"
oldestEvent = arrow.get("06/11/2023 4:00", "D/M/YYYY H:m")
def appendStringInPath(filePath, str2append):
path = Path(filePath)
return path.with_stem(f"{path.stem}_{str2append}")
with open(calendarPath, 'r') as icsFile:
ics_text = icsFile.read()
c = Calendar(ics_text)
def anonymize ():
out = Calendar()
anomymized = 0
kept = 0
skiped = 0
for e in c.events:
new = Event
if e.begin < oldestEvent:
skiped += 1
continue
elif e.name.startswith(('devWeb', 'humaNum', '3D', 'CM', 'editathon', 'Impact')):
kept += 1
newlocation = e.location
newname = e.name
else:
newlocation = "private"
newname = "private"
anomymized += 1
start = e.begin.clone()
end = e.end.clone()
out.events.add(Event(
name=newname,
location = newlocation,
begin = e.begin,
end= e.end,
))
print(f"{kept} events kept \n{anomymized} events anomymized \n{skiped} events skiped")
with open(appendStringInPath(calendarPath, 'edited'), 'w') as f:
f.writelines(out.serialize())
def printcalendar():
skiped = 0
for e in c.events:
new = Event
if e.begin < oldestEvent:
skiped += 1
continue
else:
print(f"{e.name}\n\t{e.begin.format('DD-MM HH:mm')}-{e.end.format('HH:mm')}\n\t{e.location}\n")
printcalendar()