informaticage

Hospitalized counter api

Dec 7th, 2021
763
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import requests
  2. import json
  3.  
  4. # https://api.covidtracking.com/v1/states/daily.json
  5. covid_data_server = "https://api.covidtracking.com/v1/"
  6. covid_data_daily_request = "states/daily.json"
  7.  
  8. # DRY = Dont Repeat Yourself
  9. data_retieved = requests.get(covid_data_server + covid_data_daily_request)
  10.  
  11. if(data_retieved.status_code == 200):
  12.   parsed_data = json.loads(data_retieved.text)
  13.  
  14. hospitalizedSum = 0
  15. hospitalizedCounter = 0
  16. for state in parsed_data:
  17.   if(state['hospitalizedCurrently']):
  18.     hospitalizedSum = hospitalizedSum + state['hospitalizedCurrently']
  19.     hospitalizedCounter = hospitalizedCounter + 1
  20.  
  21.   print("State:", state['state'],"\nPositive:", state['positive'], "\nDeaths:", state['death'], "\nHospitalized:", state['hospitalizedCurrently'], end="\n\n")
  22.  
  23. print("Hospitalized average: ", hospitalizedSum / hospitalizedCounter)
RAW Paste Data