Skip to content

Commit

Permalink
simplify and update weather api
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanVnucec committed Oct 4, 2024
1 parent 1ebc207 commit a13fdbf
Show file tree
Hide file tree
Showing 21 changed files with 114 additions and 821 deletions.
18 changes: 0 additions & 18 deletions .github/workflows/README.md

This file was deleted.

34 changes: 0 additions & 34 deletions .github/workflows/unit_tests.yml

This file was deleted.

42 changes: 6 additions & 36 deletions .github/workflows/weather_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,28 @@ name: Weather check

on:
schedule:
# Run every 25th minute
- cron: '*/25 * * * *'
# Run every day at 3:00 UTC (5:00 CEST)
- cron: '0 3 * * *'

workflow_dispatch:

jobs:
run:
runs-on: ubuntu-20.04
# if there is no artifact to download
continue-on-error: true
env:
ACTION_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"

steps:
- uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f

# Fix Python version. Probably works with other versions.
- uses: actions/setup-python@dc73133d4da04e56a135ae2246682783cc7c7cb6
with:
python-version: '3.8.5'

# This step is using CREDENTIALS and RECEIVERS Github Actions secrets.
# View the README.md file for instructions about secrets contents.
- name: Create Credentials and Receivers files
- name: Setup environment variables
env:
CREDENTIALS: ${{ secrets.CREDENTIALS }}
SENDER_EMAIL: ${{ secrets.SENDER_EMAIL }}
SENDER_PASSWORD: ${{ secrets.SENDER_PASSWORD }}
RECEIVERS: ${{ secrets.RECEIVERS }}
run: |
echo "$CREDENTIALS" > credentials/credentials.yaml
echo "$RECEIVERS" > credentials/receivers.txt
- name: Install requirements
run: make init

# if Download exec timetable step failed still run the script
- name: Run main application
run: make run

# This step uses Github Actions secrets FAIL_MAIL_USERNAME and FAIL_MAIL_PASSWORD
# which are Gmail username and password respectively.
#- name: Send an email alert if there are any failed steps
# if: failure()
# uses: dawidd6/action-send-mail@db36373cbed0fba7d5e12c338b580277550bdba1
# with:
# server_address: smtp.gmail.com
# server_port: 465
# username: ${{ secrets.FAIL_MAIL_USERNAME }}
# password: ${{ secrets.FAIL_MAIL_PASSWORD }}
# subject: rain_alert app run ${{ github.run_number }} failed
# # send to itself
# to: ${{ secrets.FAIL_MAIL_USERNAME }}
# from: https://github.com/IvanVnucec/rain_alert
# body: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
# # TODO: Add the workflow logs to the attachments
# #attachments:
run: python3 main.py
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
venv
__pycache__
credentials/credentials.yaml
credentials/receivers.txt
logs/exec_timetable.json.aes
.vscode
15 changes: 0 additions & 15 deletions .vscode/launch.json

This file was deleted.

8 changes: 0 additions & 8 deletions .vscode/settings.json

This file was deleted.

30 changes: 0 additions & 30 deletions Makefile

This file was deleted.

117 changes: 13 additions & 104 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,113 +1,22 @@
# rain_alert

[![App running](https://github.com/IvanVnucec/rain_alert/actions/workflows/weather_check.yml/badge.svg?branch=master&event=schedule)](https://github.com/IvanVnucec/rain_alert/actions/workflows/weather_check.yml)

# rain_alert
You will not forget your umbrella anymore. :umbrella:
You will not forget your :umbrella: anymore.

## About
Check every morning at 5 AM local time if it will be raining that day, if yes
send an email with forecast message like this:
<html>
<table>
<tr>
<th>Hour [h]</th>
<th>Probability [%]</th>
</tr>
<tr>
<td>6</td>
<td id="CELL0">0</td>
</tr>
<tr>
<td>7</td>
<td id="CELL1">0</td>
</tr>
<tr>
<td>8</td>
<td id="CELL2">0</td>
</tr>
<tr>
<td>9</td>
<td id="CELL3">0</td>
</tr>
<tr>
<td>10</td>
<td id="CELL4">10</td>
</tr>
<tr>
<td>11</td>
<td id="CELL5">22</td>
</tr>
<tr>
<td>12</td>
<td id="CELL6">35</td>
</tr>
<tr>
<td>13</td>
<td id="CELL7">60</td>
</tr>
<tr>
<td>14</td>
<td id="CELL8">86</td>
</tr>
<tr>
<td>15</td>
<td id="CELL9">100</td>
</tr>
<tr>
<td>16</td>
<td id="CELL10">100</td>
</tr>
<tr>
<td>17</td>
<td id="CELL11">100</td>
</tr>
<tr>
<td>18</td>
<td id="CELL12">100</td>
</tr>
<tr>
<td>19</td>
<td id="CELL13">72</td>
</tr>
<tr>
<td>20</td>
<td id="CELL14">36</td>
</tr>
<tr>
<td>21</td>
<td id="CELL15">5</td>
</tr>
<tr>
<td>22</td>
<td id="CELL16">0</td>
</tr>
<tr>
<td>23</td>
<td id="CELL17">0</td>
</tr>
</table>
</html>

Check the weather at 5AM Zagreb time and send an email if it will rain today.

## Get started
0. Create Gmail account and enable the Less secure app access and also create an OpenWeather API Key.
1. Create `credentials/credentials.yaml` file and put Gmail and OpenWeather credentials from step 0.
```
senderEmail: <sender Gmail email>
senderPassword: <Gmail email password>
openWeatherApiKey: <OpenWeather API key>
```
2. Create `credentials/receivers.txt` file put in email subscribers. For example:
```
[email protected], Zagreb
[email protected], Berlin
[email protected], Milwaukee
[email protected], Mobile Alabama
[email protected], Nashville Tennessee
[email protected], Nashville Indiana
```
3. Run the app using Makefile as `make run`
4. (Recommended) You can schedule the script to run on GitHub servers like we did in
[our GitHub Actions CI workflow](https://github.com/IvanVnucec/rain_alert/blob/master/.github/workflows/weather_check.yml).
See the [Instructions](./.github/workflows/README.md) for more info.

1. Create Gmail account and enable the Less secure app access.
2. Add the following environment variables to GitHub actions:
- `SENDER_EMAIL` - sender Gmail email
- `SENDER_PASSWORD` - Gmail email password
- `RECEIVERS` - list of email addresses to send the alert to
3. Run the GitHub Action workflow manually to check if everything is working.

## License

[MIT](LICENSE.md)
Empty file removed credentials/.gitkeep
Empty file.
Loading

0 comments on commit a13fdbf

Please sign in to comment.