Last active
June 13, 2020 12:46
-
-
Save devmnj/8bb6dab968e918ab958e207afede040e to your computer and use it in GitHub Desktop.
Create a covid-19 live status using API in Python
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
| import urllib2 | |
| import json | |
| from datetime import datetime, timedelta | |
| def printData(data): | |
| jsonData = json.loads(data) | |
| print('Printing Json Data....') | |
| for d in jsonData: | |
| s = str(d["date"]) | |
| dt=datetime(year=int(s[0:4]), month=int(s[4:6]), day=int(s[6:8])) | |
| print("Date :" + str(dt)) | |
| print("State :" + d["state"]) | |
| print("Positive :" + str(d["positive"])) | |
| print("Negetive :" + str(d["negative"])) | |
| print("Pending :" + str(d["pending"])) | |
| print("Hospitalized [Today] :" + str(d["hospitalizedCurrently"])) | |
| print("Hospitalized [All] :" + str(d["hospitalizedCumulative"])) | |
| print("Died :" + str(d["death"])) | |
| print("Recoverd :" + str(d["recovered"])) | |
| print('---------------------------------------') | |
| def main(): | |
| urldata = 'https://covidtracking.com/api/v1/states/current.json' | |
| weburl = urllib2.urlopen(urldata) | |
| print("result code :" + str(weburl.getcode())) | |
| if (weburl.getcode() == 200): | |
| data = weburl.read() | |
| printData(data) | |
| else: | |
| print "Some server related error occurs" | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment