diff --git a/.github/workflows/run_application.yml b/.github/workflows/run_application.yml new file mode 100644 index 0000000..9683dc4 --- /dev/null +++ b/.github/workflows/run_application.yml @@ -0,0 +1,32 @@ +name: Run Application + +on: + schedule: + - cron: '0 4 * * *' + +jobs: + run_application: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - uses: astral-sh/setup-uv@v3 + + - name: Install Python + run: uv python install + + - name: Install dependencies + run: uv sync --all-extras + + - name: Run application + run: uv run main.py + + - name: Commit and push report + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + git add reports/. + git commit -m "Automated commit of application output" + git push + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/utils/output.py b/utils/output.py index 8a5718f..43fb9a7 100644 --- a/utils/output.py +++ b/utils/output.py @@ -1,6 +1,9 @@ from datetime import datetime +from os import makedirs import pytz +REPORTS_DIR = "./reports/" + # Mapping the zone names used by BC to the zone names from the legacy report # produced by Environment Canada. ZONE_NAME_MAP = { @@ -128,9 +131,10 @@ def _generate_report_text(forecast_data: dict[str, dict[str, float]]) -> tuple[s def generate_forecast_text_file(forecast_data: dict[str, dict[str, float]]) -> None: filename, output = _generate_report_text(forecast_data) + makedirs(REPORTS_DIR, exist_ok=True) - print(f"outputting to file {filename}") + print(f"outputting to file {REPORTS_DIR}{filename}") print("==============") print(output) - _write_file(filename, output) + _write_file(f"{REPORTS_DIR}{filename}", output)