export conf
This commit is contained in:
parent
cb31eab80d
commit
e08ba28075
2 changed files with 7 additions and 7 deletions
|
|
@ -8,11 +8,11 @@ from caldav import DAVClient
|
||||||
from icalendar import Calendar
|
from icalendar import Calendar
|
||||||
|
|
||||||
|
|
||||||
def safe_filename(name):
|
def safe_filename(name: str) -> str:
|
||||||
return re.sub(r"[^a-zA-Z0-9._-]+", "_", name)
|
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(
|
client = DAVClient(
|
||||||
url=url,
|
url=url,
|
||||||
username=username,
|
username=username,
|
||||||
|
|
@ -25,19 +25,19 @@ def export_calendar(url, username, password, output):
|
||||||
|
|
||||||
target = None
|
target = None
|
||||||
for cal in calendars:
|
for cal in calendars:
|
||||||
if cal.name == output["calendar"]:
|
if cal.name == calendar:
|
||||||
target = cal
|
target = cal
|
||||||
break
|
break
|
||||||
|
|
||||||
if target is None:
|
if target is None:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
f"Calendar '{output['calendar']}' not found for {username}"
|
f"Calendar '{calendar}' not found for {username}"
|
||||||
)
|
)
|
||||||
|
|
||||||
print(f"Exporting {username}/{target.name}")
|
print(f"Exporting {username}/{target.name}")
|
||||||
|
|
||||||
result = Calendar()
|
result = Calendar()
|
||||||
result.add("prodid", "-//CalDAV Export//")
|
result.add("prodid", f"-//{calendar} calendar export//")
|
||||||
result.add("version", "2.0")
|
result.add("version", "2.0")
|
||||||
|
|
||||||
objects = target.objects()
|
objects = target.objects()
|
||||||
|
|
@ -71,7 +71,7 @@ def main():
|
||||||
output_dir.mkdir(parents=True, exist_ok=True)
|
output_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
combined = Calendar()
|
combined = Calendar()
|
||||||
combined.add("prodid", "-//CalDAV Export Combined//")
|
combined.add("prodid", "-//Combined calendar//")
|
||||||
combined.add("version", "2.0")
|
combined.add("version", "2.0")
|
||||||
|
|
||||||
for entry in config["calendars"]:
|
for entry in config["calendars"]:
|
||||||
|
|
@ -82,7 +82,7 @@ def main():
|
||||||
entry["url"],
|
entry["url"],
|
||||||
username,
|
username,
|
||||||
password,
|
password,
|
||||||
entry,
|
entry["calendar"],
|
||||||
)
|
)
|
||||||
|
|
||||||
filename = output_dir / f"{safe_filename(entry['calendar'])}.ics"
|
filename = output_dir / f"{safe_filename(entry['calendar'])}.ics"
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Reference in a new issue