fix saving blackouts.json
This commit is contained in:
17
.github/workflows/run-script.yml
vendored
17
.github/workflows/run-script.yml
vendored
@@ -1,13 +1,13 @@
|
|||||||
name: Run Script
|
name: Run Script
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
schedule:
|
schedule:
|
||||||
- cron: "30 */3 * * *"
|
- cron: "30 */3 * * *"
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
run-script:
|
run-script:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -32,7 +32,18 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
BARGHEMAN_TOKEN: ${{ secrets.BARGHEMAN_TOKEN }}
|
BARGHEMAN_TOKEN: ${{ secrets.BARGHEMAN_TOKEN }}
|
||||||
EITAAYAR_TOKEN: ${{ secrets.EITAAYAR_TOKEN }}
|
EITAAYAR_TOKEN: ${{ secrets.EITAAYAR_TOKEN }}
|
||||||
|
BLACKOUTS_FILE: "blackouts.json"
|
||||||
BILL_IDS: ${{ secrets.BILL_IDS }}
|
BILL_IDS: ${{ secrets.BILL_IDS }}
|
||||||
CHAT_ID: ${{ secrets.CHAT_ID }}
|
CHAT_ID: ${{ secrets.CHAT_ID }}
|
||||||
run: |
|
run: |
|
||||||
python main.py
|
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
10
main.py
@@ -7,7 +7,7 @@ BARGHEMAN_TOKEN = os.getenv("BARGHEMAN_TOKEN")
|
|||||||
EITAAYAR_TOKEN = os.getenv("EITAAYAR_TOKEN")
|
EITAAYAR_TOKEN = os.getenv("EITAAYAR_TOKEN")
|
||||||
CHAT_ID = os.getenv("CHAT_ID")
|
CHAT_ID = os.getenv("CHAT_ID")
|
||||||
BILL_IDS = os.getenv("BILL_IDS", "").split(",")
|
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:
|
if not BARGHEMAN_TOKEN or not EITAAYAR_TOKEN or not CHAT_ID or len(BILL_IDS) == 0:
|
||||||
raise EnvironmentError("Environment is not ready!")
|
raise EnvironmentError("Environment is not ready!")
|
||||||
@@ -91,13 +91,7 @@ def main() -> None:
|
|||||||
if new_entries:
|
if new_entries:
|
||||||
updated_data[bill_id] = old_blackouts + new_entries
|
updated_data[bill_id] = old_blackouts + new_entries
|
||||||
|
|
||||||
if updated_data != previous_data:
|
save_blackouts(updated_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")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user