From 2b4bcf23459fe78e0507a346c48cc200a0b136dd Mon Sep 17 00:00:00 2001 From: Chris Nutter Date: Thu, 9 Jan 2025 21:53:30 -0800 Subject: [PATCH] more available args and dockerfile --- Dockerfile | 16 ++++++++++++++++ app.py | 21 +++++++++++---------- 2 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..687a60c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM python:3.11 + +WORKDIR /app +COPY app.py . +COPY requirements.txt . + +RUN pip install --no-cache-dir -r -r requirements.txt + +# Environment variables +ENV CALDAV_URL="" +ENV PASSWORD="" +ENV RA_API="" +ENV RA_USER="" +ENV CALENDAR_NAME="" + +CMD ["python3", "./app.py", "$CALDAV_URL", "$CALENDAR_NAME", "$USERNAME", "$PASSWORD", "$RA_API", "$RA_USER"] diff --git a/app.py b/app.py index 163cdc1..bae821f 100644 --- a/app.py +++ b/app.py @@ -11,7 +11,7 @@ from urllib.request import urlopen import urllib.error # Function to create calendar events from JSON data -def create_calendar_events_from_json(caldav_url, username, password, json): +def create_calendar_events_from_json(caldav_url, calendar_name, username, password, json, ra_user): try: # 1. Connect to CalDAV server client = caldav.DAVClient( @@ -22,7 +22,7 @@ def create_calendar_events_from_json(caldav_url, username, password, json): # 2. Get principal and calendar my_principal = client.principal() - my_calendar = my_principal.calendar(name="Achievement of The Week") # Replace with your calendar name + my_calendar = my_principal.calendar(name=calendar_name) # Replace with your calendar name # 3a. Read JSON data response = requests.get(json) @@ -39,7 +39,7 @@ def create_calendar_events_from_json(caldav_url, username, password, json): status = "NEEDS-ACTION" if "Unlocks" in events_data: for unlock in events_data["Unlocks"]: - if unlock["User"] == "{RA_USER}": # Replace with your username + if unlock["User"] == "{ra_user}": # Replace with your username status = "COMPLETED" break @@ -93,19 +93,20 @@ END:VCALENDAR # Usage example if __name__ == "__main__": - if len(sys.argv) != 6: - print("Usage: python3 app.py ") + if len(sys.argv) != 7: + print("Usage: python3 app.py [OPTIONAL] ") sys.exit(1) CALDAV_URL = sys.argv[1] - USERNAME = sys.argv[2] - PASSWORD = sys.argv[3] - RA_USER = sys.argv[5] - RA_API = sys.argv[4] + CALENDAR_NAME = sys.argv[2] + USERNAME = sys.argv[3] + PASSWORD = sys.argv[4] + RA_API = sys.argv[5] + RA_USER = sys.argv[6] # CalDAV server details JSON = f"https://retroachievements.org/API/API_GetAchievementOfTheWeek.php?&y={RA_API}" response = requests.get(JSON) data = response.json() - create_calendar_events_from_json(CALDAV_URL, USERNAME, PASSWORD, JSON) + create_calendar_events_from_json(CALDAV_URL, CALENDAR_NAME, USERNAME, PASSWORD, JSON, RA_USER)