export conf

This commit is contained in:
XenGi 2026-07-14 20:01:16 +02:00
commit e08ba28075
Signed by: xengi
SSH key fingerprint: SHA256:jxWM2RTHvxxcncXycwwWkP7HCWb4VREN05UGJTbIPZg
2 changed files with 7 additions and 7 deletions

View file

@ -8,11 +8,11 @@ from caldav import DAVClient
from icalendar import Calendar
def safe_filename(name):
def safe_filename(name: str) -> str:
return re.sub(r"[^a-zA-Z0-9._-]+", "_", name)
def export_calendar(url, username, password, output):
def export_calendar(url: str, username: str, password: str, calendar: str) -> Calendar:
client = DAVClient(
url=url,
username=username,
@ -25,19 +25,19 @@ def export_calendar(url, username, password, output):
target = None
for cal in calendars:
if cal.name == output["calendar"]:
if cal.name == calendar:
target = cal
break
if target is None:
raise RuntimeError(
f"Calendar '{output['calendar']}' not found for {username}"
f"Calendar '{calendar}' not found for {username}"
)
print(f"Exporting {username}/{target.name}")
result = Calendar()
result.add("prodid", "-//CalDAV Export//")
result.add("prodid", f"-//{calendar} calendar export//")
result.add("version", "2.0")
objects = target.objects()
@ -71,7 +71,7 @@ def main():
output_dir.mkdir(parents=True, exist_ok=True)
combined = Calendar()
combined.add("prodid", "-//CalDAV Export Combined//")
combined.add("prodid", "-//Combined calendar//")
combined.add("version", "2.0")
for entry in config["calendars"]:
@ -82,7 +82,7 @@ def main():
entry["url"],
username,
password,
entry,
entry["calendar"],
)
filename = output_dir / f"{safe_filename(entry['calendar'])}.ics"

Binary file not shown.