fix saving blackouts.json

This commit is contained in:
2025-06-02 00:24:49 +03:30
parent d91e4e93aa
commit 5e6573c922
2 changed files with 16 additions and 11 deletions

View File

@@ -1,13 +1,13 @@
name: Run Script
on:
push:
branches:
- main
schedule:
- cron: "30 */3 * * *"
workflow_dispatch:
permissions:
contents: write
jobs:
run-script:
runs-on: ubuntu-latest
@@ -32,7 +32,18 @@ jobs:
env:
BARGHEMAN_TOKEN: ${{ secrets.BARGHEMAN_TOKEN }}
EITAAYAR_TOKEN: ${{ secrets.EITAAYAR_TOKEN }}
BLACKOUTS_FILE: "blackouts.json"
BILL_IDS: ${{ secrets.BILL_IDS }}
CHAT_ID: ${{ secrets.CHAT_ID }}
run: |
python main.py
- name: Commit & Push updated data
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --global user.name "github-actions"
git config --global user.email "github-actions@github.com"
git add blackouts.json
git commit -m "Update outage data" || echo "Nothing to commit"
git push

10
main.py
View File

@@ -7,7 +7,7 @@ BARGHEMAN_TOKEN = os.getenv("BARGHEMAN_TOKEN")
EITAAYAR_TOKEN = os.getenv("EITAAYAR_TOKEN")
CHAT_ID = os.getenv("CHAT_ID")
BILL_IDS = os.getenv("BILL_IDS", "").split(",")
BLACKOUTS_FILE = "blackouts.json"
BLACKOUTS_FILE = os.getenv("BLACKOUTS_FILE")
if not BARGHEMAN_TOKEN or not EITAAYAR_TOKEN or not CHAT_ID or len(BILL_IDS) == 0:
raise EnvironmentError("Environment is not ready!")
@@ -91,13 +91,7 @@ def main() -> None:
if new_entries:
updated_data[bill_id] = old_blackouts + new_entries
if updated_data != previous_data:
save_blackouts(updated_data)
os.system("git config --global user.name 'github-actions'")
os.system("git config --global user.email 'github-actions@github.com'")
os.system("git add " + BLACKOUTS_FILE)
os.system("git commit -m 'Update outage data'")
os.system("git push")
save_blackouts(updated_data)
if __name__ == '__main__':