Created
May 19, 2020 07:27
-
-
Save 0187773933/5e60aa67e15886f5e924e74a8658ddd4 to your computer and use it in GitHub Desktop.
Prints Ohio Covid-19 Info from covidtracking.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import json | |
import requests | |
from pprint import pprint | |
from datetime import datetime , timedelta , time | |
from time import localtime, strftime , sleep | |
from pytz import timezone | |
eastern_tz = timezone( "US/Eastern" ) | |
def get_latest_state_info(): | |
response = requests.get( "https://covidtracking.com/api/v1/states/daily.json" ) | |
return response.json() | |
def get_ohio( state_info ): | |
ohio = [ i for i in state_info if i[ "state" ] == "OH" ] | |
for index , day in enumerate( ohio ): | |
day["date"] = datetime.strptime( str( day["date"] ) , "%Y%m%d" ) | |
ohio = sorted( ohio , key=lambda k: k['date'] ) | |
return ohio | |
def get_ohio_last_week( ohio ): | |
last_week = ohio[ -7: ] | |
return last_week | |
def print_ohio_daily_totals( ohio ): | |
for index , day in enumerate( ohio ): | |
print( f"{day['date']:%Y-%m-%d} === {day['total']} === Increase === {day['positiveIncrease']}" ) | |
def print_ohio_last_week_daily_totals( ohio_last_week ): | |
for index , day in enumerate( ohio_last_week ): | |
print( f"{day['date']:%Y-%m-%d} === {day['total']}" ) | |
if __name__ == '__main__': | |
state_info = get_latest_state_info() | |
ohio = get_ohio( state_info ) | |
print_ohio_daily_totals( ohio ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment