Skip to content

Commit

Permalink
add cron workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Stelios Daveas authored and Stelios Daveas committed Oct 29, 2023
1 parent e3f00c5 commit 6dae850
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 22 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/cron.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Daily Weather Forecast

on:
schedule:
# Runs every hour
- cron: '0 * * * *'
workflow_dispatch:

jobs:
forecast:
runs-on: ubuntu-latest
environment: API_KEYS

steps:
- name: Echo variables
run: |
echo hours: ${{ vars.GC_TIMEDELTA_HOURS }}
echo lat: ${{ vars.LAT }}
echo lon: ${{ vars.LON }}
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.11

- name: Install Pipenv
run: pip install pipenv

- name: Install dependencies using Pipenv
run: |
pipenv install --deploy --ignore-pipfile
- name: Run forecast.py using Pipenv
run: pipenv run python forecast.py
env:
TG_BOT_TOKEN: ${{ secrets.TG_BOT_TOKEN }}
TG_CHAT_ID: ${{ secrets.TG_CHAT_ID }}
OW_API_KEY: ${{ secrets.OW_API_KEY }}
GC_API_KEY: ${{ secrets.GC_API_KEY }}
GC_ID: ${{ secrets.GC_ID }}
GC_TIMEDELTA_HOURS: ${{ vars.GC_TIMEDELTA_HOURS }}
LAT: ${{ vars.LAT }}
LON: ${{ vars.LON }}

1 change: 0 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# Google Calendar
GC_API_KEY = os.getenv("GC_API_KEY")
GC_ID = os.getenv("GC_ID")
GC_EVENT_KEYWORDS = os.getenv("GC_EVENT_KEYWORDS")
GC_TIMEDELTA_HOURS = os.getenv("GC_TIMEDELTA_HOURS")

# Location
Expand Down
39 changes: 18 additions & 21 deletions forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def main():


def get_calendar_events():
keywords = config.GC_EVENT_KEYWORDS
timedelta_hours = int(config.GC_TIMEDELTA_HOURS)

service = build("calendar", "v3", developerKey=config.GC_API_KEY)
Expand All @@ -43,27 +42,25 @@ def get_calendar_events():
start_date = datetime.utcnow().isoformat() + "Z" # 'Z' indicates UTC time
end_date = (datetime.utcnow() + timedelta(hours=timedelta_hours)).isoformat() + "Z"

for keyword in keywords:
events_result = (
service.events()
.list(
calendarId=config.GC_ID,
q=keyword,
timeMin=start_date,
timeMax=end_date,
)
.execute()
events_result = (
service.events()
.list(
calendarId=config.GC_ID,
timeMin=start_date,
timeMax=end_date,
)
.execute()
)

events = events_result.get("items", [])
for event in events:
matching_events.append(
{
"summary": event["summary"],
"start": event["start"].get("dateTime", event["start"].get("date")),
"location": event["location"],
}
)

events = events_result.get("items", [])
for event in events:
matching_events.append(
{
"summary": event["summary"],
"start": event["start"].get("dateTime", event["start"].get("date")),
"location": event["location"],
}
)

return matching_events

Expand Down

0 comments on commit 6dae850

Please sign in to comment.