more available args and dockerfile

master
Chris Nutter 2025-01-09 21:53:30 -08:00
parent ad609e913e
commit 2b4bcf2345
2 changed files with 27 additions and 10 deletions

16
Dockerfile Normal file
View File

@ -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"]

21
app.py
View File

@ -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 <caldav_url> <username> <password> <ra_api_key>")
if len(sys.argv) != 7:
print("Usage: python3 app.py <caldav_url> <calendar_name> <username> <password> <ra_api_key> [OPTIONAL] <ra_username>")
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)