Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import json
- # https://api.covidtracking.com/v1/states/daily.json
- covid_data_server = "https://api.covidtracking.com/v1/"
- covid_data_daily_request = "states/daily.json"
- # DRY = Dont Repeat Yourself
- data_retieved = requests.get(covid_data_server + covid_data_daily_request)
- if(data_retieved.status_code == 200):
- parsed_data = json.loads(data_retieved.text)
- hospitalizedSum = 0
- hospitalizedCounter = 0
- for state in parsed_data:
- if(state['hospitalizedCurrently']):
- hospitalizedSum = hospitalizedSum + state['hospitalizedCurrently']
- hospitalizedCounter = hospitalizedCounter + 1
- print("State:", state['state'],"\nPositive:", state['positive'], "\nDeaths:", state['death'], "\nHospitalized:", state['hospitalizedCurrently'], end="\n\n")
- print("Hospitalized average: ", hospitalizedSum / hospitalizedCounter)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement