Fix purging of future ical appointments

This commit is contained in:
sqozz 2023-03-01 09:25:24 +01:00
parent 83c1fe95b1
commit cebd945d45
1 changed files with 11 additions and 8 deletions

View File

@ -3,6 +3,8 @@ import icalendar
import datetime import datetime
import requests import requests
import urllib import urllib
import glob
import pytz
import json import json
import os import os
@ -77,15 +79,16 @@ for trash_type in trash_types:
if not os.path.exists(trash_type_folder): if not os.path.exists(trash_type_folder):
os.makedirs(trash_type_folder) os.makedirs(trash_type_folder)
for f in next(os.walk(trash_type_folder), (None, None, []))[2]: for f in os.listdir(trash_type_folder):
ical_path = os.path.join(trash_type_folder, f) ical_path = os.path.join(trash_type_folder, f)
with open(ical_path, "rb") as fh: if os.path.isfile(ical_path):
try: with open(ical_path, "rb") as fh:
cal = icalendar.Calendar.from_ical(fh.read()) try:
except ValueError: cal = icalendar.Calendar.from_ical(fh.read())
print("{} is not an parsable ical file".format(ical_path)) except ValueError:
continue print("{} is not an parsable ical file".format(ical_path))
if cal.walk()[1]["DTSTAMP"].dt.year == current_year: continue
if cal.walk()[1]["DTSTART"].dt > datetime.datetime.now(pytz.utc):
os.remove(ical_path) os.remove(ical_path)
radicale_prop_file = os.path.join(trash_type_folder, ".Radicale.props") radicale_prop_file = os.path.join(trash_type_folder, ".Radicale.props")