diff --git a/.github/workflows/update_events.yml b/.github/workflows/update_events.yml index 5384a41e1..469a57b16 100644 --- a/.github/workflows/update_events.yml +++ b/.github/workflows/update_events.yml @@ -2,19 +2,17 @@ name: Update Events on: schedule: - cron: '0 0 * * *' # Runs every day at 00:00 UTC + workflow_dispatch: jobs: - update-events: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.8 - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - - name: Run script - run: python ./scripts/events_updater.py # Replace with the path to your script \ No newline at end of file + update-events: + runs-on: ubuntu-latest + container: + image: python:3.9-slim-buster + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Install dependencies + run: pip install --no-cache-dir -r requirements.txt + - name: Run script + run: python .scripts/events_updater.py \ No newline at end of file diff --git a/.scripts/events_updater.py b/.scripts/events_updater.py index a29aa4f91..6d4422930 100644 --- a/.scripts/events_updater.py +++ b/.scripts/events_updater.py @@ -13,10 +13,18 @@ 'New Delhi': 'Asia/Kolkata', 'Tokyo': 'Asia/Tokyo' } -# Define the directories -events_dir = "../docs/events/" -i18n_dir = "../i18n/ja/docusaurus-plugin-content-docs/current/events/" +import os + +# Get the directory of the script +script_dir = os.path.dirname(os.path.realpath(__file__)) + +# Get the parent directory +parent_dir = os.path.dirname(script_dir) +# Construct the paths to the files +events_index_path = os.path.join(parent_dir, 'docs/events/index.md') +i18n_index_path = os.path.join(parent_dir, 'i18n/ja/docusaurus-plugin-content-docs/current/events/index.md') +# Use the paths to open the files # URLs of your public Google Calendars' iCals urls = [ @@ -86,7 +94,7 @@ # Read existing events from the current markdown files existing_events = {} -with open('../docs/events/index.md', 'r') as f, open('../i18n/ja/docusaurus-plugin-content-docs/current/events/index.md', 'r') as f_i18n: +with open(events_index_path, 'r') as f, open(i18n_index_path, 'r') as f_i18n: lines = f.readlines() + f_i18n.readlines() for line in lines: if '|' in line: @@ -94,7 +102,7 @@ existing_events[event] = True # Write upcoming events to the current markdown files -with open('../docs/events/index.md', 'w') as f, open('../i18n/ja/docusaurus-plugin-content-docs/current/events/index.md', 'w') as f_i18n: +with open(events_index_path, 'w') as f, open(i18n_index_path, 'w') as f_i18n: f.write("# Events\n\n") f.write("The following events are upcoming:\n\n") f.write("| Event | Date | Time| Location |\n") @@ -104,7 +112,6 @@ f_i18n.write("このページでは、プロジェクトに関連するイベントを紹介します。\n\n") f_i18n.write("| イベント | 日付 |時間| 場所 |\n") f_i18n.write("| --- | --- | --- |---|\n") - for start_time, summary in events: if now < start_time < one_month_later and summary not in existing_events: @@ -118,8 +125,10 @@ filename += "-" + str(count) event_counts[day] -= 1 filename += ".md" - if not os.path.exists(events_dir + filename): - with open(events_dir + filename, 'w') as event_file: + + # Check if the English markdown file exists + if not os.path.exists(filename): + with open(filename, 'w') as event_file: event_file.write(f"## {summary}\n") event_file.write(f"Start time: {start_time}\n\n") event_file.write("## When is this event?\n\n") @@ -128,15 +137,17 @@ local_end_time = (start_time + timedelta(hours=1)).astimezone(timezone(tz)) event_file.write(f"- {local_start_time.strftime('%Y-%m-%dT%H:%M')}/{local_end_time.strftime('%H:%M')} for {city}\n") - # Check if the translated markdown file exists in the i18n directory - if not os.path.exists(i18n_dir + filename): - with open(i18n_dir + filename, 'w') as event_file: + # Check if the translated markdown file exists + if not os.path.exists(filename): + with open(filename, 'w') as event_file: event_file.write(f"## {summary}\n") # Replace with translated summary event_file.write(f"Start time: {start_time}\n\n") event_file.write("## When is this event?\n\n") for city, tz in timezones.items(): local_start_time = start_time.astimezone(timezone(tz)) local_end_time = (start_time + timedelta(hours=1)).astimezone(timezone(tz)) - event_file.write(f"- {local_start_time.strftime('%Y-%m-%dT%H:%M')}/{local_end_time.strftime('%H:%M')} for {city}\n") # Write the event to the index.md file + event_file.write(f"- {local_start_time.strftime('%Y-%m-%dT%H:%M')}/{local_end_time.strftime('%H:%M')} for {city}\n") + + # Write the event to the index.md file f.write(f"| [{summary}]({filename}) | [{start_time.strftime('%Y-%m-%d')}]({filename}) | [Time](https://www.timeanddate.com/worldclock/fixedtime.html?msg={summary.replace(' ', '+')}&iso={start_time.strftime('%Y%m%dT%H%M')}&p1=1440&ah=1) | [Register](#) |\n") f_i18n.write(f"| [{summary}]({filename}) | [{start_time.strftime('%Y-%m-%d')}]({filename}) | [Time](https://www.timeanddate.com/worldclock/fixedtime.html?msg={summary.replace(' ', '+')}&iso={start_time.strftime('%Y%m%dT%H%M')}&p1=1440&ah=1) | [Register](#) |\n") # Replace with translated summary \ No newline at end of file diff --git a/.scripts/requirements.txt b/.scripts/requirements.txt index aaf9d3f94..45772c31f 100644 --- a/.scripts/requirements.txt +++ b/.scripts/requirements.txt @@ -1,2 +1,3 @@ +requests icalendar python-dateutil \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 340dd15d4..7ddeee440 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ icalendar python-dateutil +requests \ No newline at end of file