Skip to content

Instantly share code, notes, and snippets.

@hwayne
Created March 13, 2023 19:59
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hwayne/cb1dbbed66a1d1957d2ae6de5436da3a to your computer and use it in GitHub Desktop.
Save hwayne/cb1dbbed66a1d1957d2ae6de5436da3a to your computer and use it in GitHub Desktop.
Script that notifies me when a cubs game is happening
# This is running on an aws lambda instance with a CloudWatch trigger:
# Trigger is cron(0 17 * * ? *)
# CSV is from https://www.mlb.com/cubs/schedule/downloadable-schedule
import json
from urllib.request import urlopen, Request
from urllib.parse import urlencode
from os import getenv
from csv import DictReader
from datetime import datetime
from pathlib import Path
import boto3
def lambda_handler(event, context):
# TODO have separate code paths for daily (pushover) and on-demand (http response)
# https://docs.aws.amazon.com/lambda/latest/dg/urls-invocation.html
today = datetime.today().strftime(r"%m/%d/%y")
csv = DictReader(Path('./GameTicketPromotionPrice.csv').open())
for row in csv:
if row['START DATE'] == today:
start, end = row['START TIME'], row['END TIME']
message = f"Cubs Game: {start}-{end}"
url = "https://api.pushover.net/1/messages.json"
data = urlencode({'token': getenv('PUSHOVER_API'),
'user': getenv('PUSHOVER_USER'),
'message': message,
'title': "Game warning"})
data = data.encode('ascii')
with urlopen(url, data=data) as f:
pass
return {
'statusCode': 200,
'body': json.dumps(f.status)
}
return {
'statusCode': 200,
'body': "No game detected"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment