more available args and dockerfile
parent
ad609e913e
commit
2b4bcf2345
|
@ -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
21
app.py
|
@ -11,7 +11,7 @@ from urllib.request import urlopen
|
||||||
import urllib.error
|
import urllib.error
|
||||||
|
|
||||||
# Function to create calendar events from JSON data
|
# 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:
|
try:
|
||||||
# 1. Connect to CalDAV server
|
# 1. Connect to CalDAV server
|
||||||
client = caldav.DAVClient(
|
client = caldav.DAVClient(
|
||||||
|
@ -22,7 +22,7 @@ def create_calendar_events_from_json(caldav_url, username, password, json):
|
||||||
|
|
||||||
# 2. Get principal and calendar
|
# 2. Get principal and calendar
|
||||||
my_principal = client.principal()
|
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
|
# 3a. Read JSON data
|
||||||
response = requests.get(json)
|
response = requests.get(json)
|
||||||
|
@ -39,7 +39,7 @@ def create_calendar_events_from_json(caldav_url, username, password, json):
|
||||||
status = "NEEDS-ACTION"
|
status = "NEEDS-ACTION"
|
||||||
if "Unlocks" in events_data:
|
if "Unlocks" in events_data:
|
||||||
for unlock in events_data["Unlocks"]:
|
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"
|
status = "COMPLETED"
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -93,19 +93,20 @@ END:VCALENDAR
|
||||||
# Usage example
|
# Usage example
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
if len(sys.argv) != 6:
|
if len(sys.argv) != 7:
|
||||||
print("Usage: python3 app.py <caldav_url> <username> <password> <ra_api_key>")
|
print("Usage: python3 app.py <caldav_url> <calendar_name> <username> <password> <ra_api_key> [OPTIONAL] <ra_username>")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
CALDAV_URL = sys.argv[1]
|
CALDAV_URL = sys.argv[1]
|
||||||
USERNAME = sys.argv[2]
|
CALENDAR_NAME = sys.argv[2]
|
||||||
PASSWORD = sys.argv[3]
|
USERNAME = sys.argv[3]
|
||||||
RA_USER = sys.argv[5]
|
PASSWORD = sys.argv[4]
|
||||||
RA_API = sys.argv[4]
|
RA_API = sys.argv[5]
|
||||||
|
RA_USER = sys.argv[6]
|
||||||
|
|
||||||
# CalDAV server details
|
# CalDAV server details
|
||||||
JSON = f"https://retroachievements.org/API/API_GetAchievementOfTheWeek.php?&y={RA_API}"
|
JSON = f"https://retroachievements.org/API/API_GetAchievementOfTheWeek.php?&y={RA_API}"
|
||||||
response = requests.get(JSON)
|
response = requests.get(JSON)
|
||||||
data = response.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)
|
||||||
|
|
Loading…
Reference in New Issue