Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,29 @@ on:
branches:
- main
workflow_dispatch:
inputs:
force_notify:
description: 'Force send notification'
required: false
default: false
type: boolean
schedule:
- cron: '17 * * * *' # At 00:00 on Monday
- cron: '10 0,6,12 * * *' # 08:10 / 14:10 / 20:10 UTC+8 daily (10-min offset to avoid :00 peak)

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repo content
uses: actions/checkout@v2
uses: actions/checkout@v7

- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v7
with:
python-version: '3.10'

- name: Cache Python packages
uses: actions/cache@v3
uses: actions/cache@v6
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml', '**/uv.lock') }}
Expand All @@ -43,6 +49,7 @@ jobs:
PASSPORT_NUMBER: ${{ secrets.PASSPORT_NUMBER }}
SURNAME: ${{ secrets.SURNAME }}
TIMEZONE: ${{ secrets.TIMEZONE }}
# ACTIVE_HOURS: ${{ secrets.ACTIVE_HOURS }}
FROM: ${{ secrets.FROM }}
TO: ${{ secrets.TO }}
PASSWORD: ${{ secrets.PASSWORD }}
Expand All @@ -51,10 +58,11 @@ jobs:
TG_CHAT_ID: ${{ secrets.TG_CHAT_ID }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
FORCE_NOTIFY: ${{ github.event.inputs.force_notify || 'false' }}
run: uv run trigger.py

- name: Upload status artifact
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v7
with:
name: status-artifact
path: status_record.json
21 changes: 14 additions & 7 deletions CEACStatusBot/notification/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,17 @@ def send(self) -> None:
# Load the previous statuses from the file
statuses = self.__load_statuses()

# Check if the current status is different from the last recorded status
if not statuses or current_status != statuses[-1].get("status", None) or current_last_updated != statuses[-1].get("last_updated", None):
force_notify = os.getenv("FORCE_NOTIFY", "").lower() in ("1", "true", "yes")
# Check if the current status is different from the last recorded status,
# or if notifications are forced for manual testing
status_changed = (
not statuses
or current_status != statuses[-1].get("status", None)
or current_last_updated != statuses[-1].get("last_updated", None)
)
if force_notify or status_changed:
if force_notify:
print("FORCE_NOTIFY set - sending notification despite unchanged status.")
self.__save_current_status(current_status, current_last_updated)
self.__send_notifications(res)
else:
Expand All @@ -74,11 +83,9 @@ def __load_statuses(self) -> list:

def __save_current_status(self, status: str, last_updated: str) -> None:
statuses = self.__load_statuses()
statuses.append({
"status": status,
"last_updated": last_updated,
"date": datetime.datetime.now().isoformat()
})
statuses.append(
{"status": status, "last_updated": last_updated, "date": datetime.datetime.now().isoformat()}
)

with open(self.__status_file, "w") as file:
json.dump({"statuses": statuses}, file)
Expand Down