Skip to content

Instantly share code, notes, and snippets.

@atucom
Created March 5, 2020 01:48
Show Gist options
  • Save atucom/cf84a3acea8a64cf9a25996be07a04df to your computer and use it in GitHub Desktop.
Save atucom/cf84a3acea8a64cf9a25996be07a04df to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# crappy script to check colorado's covid tracking site. Run once per day via cron or cloudwatch/lambda
import bs4
import requests
def check_co_gov_site():
url = 'https://www.colorado.gov/pacific/cdphe/2019-novel-coronavirus'
reply = requests.get(url)
soup = bs4.BeautifulSoup(reply.text, features='html.parser')
# This is hyper-fragile, but their site kinda sucks so whatever
positive_covid_cases_html = soup.select('#content-inner > div > div.field.field-name-body.field-type-text-with-summary.field-label-hidden > div > div > div:nth-child(7) > table > tbody > tr:nth-child(1) > td:nth-child(2) > p > span > span > span')
positive_covid_cases = int(positive_covid_cases_html[0].text)
return positive_covid_cases
def lambda_handler(event, context):
import boto3 # only call if script is being used in lambda, otherwise don't bother people
ACCESS_SECRET_KEY = 'ASDASDASDASDASDASDASD'
ACCESS_KEY_ID = 'AKIAASDASDASDASD'
phone_number = "11235551234"
sns_client = boto3.client('sns',\
aws_access_key_id=ACCESS_KEY_ID,\
aws_secret_access_key=ACCESS_SECRET_KEY,\
region_name = 'us-east-1'
)
positive_covid_cases = check_co_gov_site()
if positive_covid_cases > 0:
message = " CO reported {} positive covid cases".format(positive_covid_cases)
sns_client.publish(PhoneNumber=phone_number, Message=message)
if __name__ == "__main__":
positive_covid_cases = check_co_gov_site()
if positive_covid_cases > 0:
print('ZOOOOOMBIES CORAL')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment