added try_catch for dotenv parsing and made print formatting more consistent
This commit is contained in:
+14
-9
@@ -7,12 +7,15 @@ from zoneinfo import ZoneInfo
|
||||
from pathlib import Path
|
||||
|
||||
# load settings from .env
|
||||
load_dotenv()
|
||||
CALDAV_URL = os.environ["CALDAV_URL"]
|
||||
CALDAV_USER = os.environ["CALDAV_USER"]
|
||||
CALDAV_PASS = os.environ["CALDAV_PASS"]
|
||||
MODULES = os.environ["SUBJECTS"].split(",")
|
||||
TIME_ZONE = ZoneInfo(os.environ.get("TIMEZONE", "Europe/Berlin"))
|
||||
try:
|
||||
load_dotenv()
|
||||
CALDAV_URL = os.environ["CALDAV_URL"]
|
||||
CALDAV_USER = os.environ["CALDAV_USER"]
|
||||
CALDAV_PASS = os.environ["CALDAV_PASS"]
|
||||
MODULES = os.environ["SUBJECTS"].split(",")
|
||||
TIME_ZONE = ZoneInfo(os.environ.get("TIMEZONE", "Europe/Berlin"))
|
||||
except Exception:
|
||||
print("Failed to read settings from .env!\nTake a look at .env.example for the required structure!")
|
||||
|
||||
# apply
|
||||
client = caldav.DAVClient(
|
||||
@@ -63,11 +66,13 @@ if backlog_path.exists():
|
||||
# and reattempt sync
|
||||
try:
|
||||
calendar.add_event(dtstart=start, dtend=end, summary=mod)
|
||||
print(f"synced event '{mod}'")
|
||||
print(f"# synced event '{mod}'")
|
||||
except Exception:
|
||||
failed_synchs.append([mod,start,end])
|
||||
print(f"failed to sync event '{mod}'")
|
||||
|
||||
# overwrite file with failed syncs (if there are any)
|
||||
backlog_path.unlink(missing_ok=True) # delete old file
|
||||
if failed_synchs:
|
||||
with open(backlog_path, "w") as fd:
|
||||
for mod, start, end in failed_synchs:
|
||||
@@ -112,11 +117,11 @@ end = datetime.now(TIME_ZONE)
|
||||
print(f"\n# Stopped at {end:%H:%M:%S}")
|
||||
ans = ""
|
||||
while ans not in ["y", "n"]:
|
||||
print("Do you want to sync this session? [y|n]")
|
||||
print("# Do you want to sync this session? [y|n]")
|
||||
ans = input("> ").lower()
|
||||
|
||||
if ans == "n":
|
||||
print("# Stopping..")
|
||||
print("Stopping..")
|
||||
exit(0)
|
||||
|
||||
# sync
|
||||
|
||||
Reference in New Issue
Block a user