Skip to content

Commit

Permalink
fix: incorrect folder relative to script
Browse files Browse the repository at this point in the history
refactor: event updating workflow and script
  • Loading branch information
albertkun committed Nov 16, 2023
1 parent 031df80 commit 08de63a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 26 deletions.
26 changes: 12 additions & 14 deletions .github/workflows/update_events.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
35 changes: 23 additions & 12 deletions .scripts/events_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -86,15 +94,15 @@

# 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:
event = line.split('|')[1].strip()
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")
Expand All @@ -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:

Expand All @@ -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")
Expand All @@ -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
1 change: 1 addition & 0 deletions .scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
requests
icalendar
python-dateutil
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
icalendar
python-dateutil
requests

0 comments on commit 08de63a

Please sign in to comment.