Skip to content

Commit

Permalink
Removed KeyError(not fully) only ones with lowcapital eg: poland will…
Browse files Browse the repository at this point in the history
… trigger keyerror but Poland will not so make first letter upper
  • Loading branch information
Aashs committed Jan 13, 2022
1 parent 0c816b9 commit 476f24c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
14 changes: 10 additions & 4 deletions api/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
from fastapi import FastAPI, Request
import uvicorn

app = FastAPI()

@app.get("/")
Expand All @@ -10,7 +11,7 @@ def dashboard():
newTime = time.time()
lastUpdate = round((newTime - float(data['lastScrapped']['lastUpdateTime']))/60)
return {
f'data last updated {lastUpdate} minute ago, a nice dashboard will be here soon....'
f'data last updated {lastUpdate} minute ago, code can be found here https://github.com/Aashs/Covid-data-scraper and for documentation about requesting data https://covid19data.tk/docs.'
}


Expand All @@ -25,7 +26,13 @@ def get_country(countryName: str):
"recovers": data["countries"][countryName]["recovers"]
}
except KeyError:
return {"Key error"}
try:
country_upper=countryName.title()
return{"cases": data["countries"][country_upper]["cases"],
"deaths": data["countries"][country_upper]["deaths"],
"recovers": data["countries"][country_upper]["recovers"]}
except KeyError:
return 'Key Error'


@app.get("/total")
Expand All @@ -44,5 +51,4 @@ def run():
uvicorn.run(app, host='0.0.0.0', port=8080)


covid19data().start()
Thread(target=run).start()
covid19data().start()
12 changes: 7 additions & 5 deletions merged.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
"""We use this script for hosting it in replit"""
import json, time, requests, uvicorn
from fastapi import FastAPI, Request
from threading import *
from bs4 import BeautifulSoup

"""We use this script on our hosting service replit 😂"""

"""Getting data on what to scrape"""
class covid19data(Thread):


def get_cases(self, link):
s = time.time()
req = requests.get(link)
Expand Down Expand Up @@ -94,7 +93,7 @@ def run(self):
json.dump(data, f, indent=3)

print('Sleeping started')
time.sleep(3600)
time.sleep(2400)

"""-------------------------------API Server-----------------------------------------"""
app = FastAPI()
Expand All @@ -106,7 +105,7 @@ def dashboard():
newTime = time.time()
lastUpdate = round((newTime - float(data['lastScrapped']['lastUpdateTime']))/60)
return {
f'data last updated {lastUpdate} minute ago, a nice dashboard will be here soon....'
f'data last updated {lastUpdate} minute ago, code can be found here https://github.com/Aashs/Covid-data-scraper and for documentation about requesting data https://covid19data.tk/docs.'
}


Expand All @@ -121,7 +120,10 @@ def get_country(countryName: str):
"recovers": data["countries"][countryName]["recovers"]
}
except KeyError:
return {"Key error"}
country_upper=countryName.title()
return{"cases": data["countries"][country_upper]["cases"],
"deaths": data["countries"][country_upper]["deaths"],
"recovers": data["countries"][country_upper]["recovers"]}


@app.get("/total")
Expand Down

0 comments on commit 476f24c

Please sign in to comment.