From 476f24cab0c4ec5405338c5e27b4b6adcd81f2c0 Mon Sep 17 00:00:00 2001
From: Aasher
Date: Thu, 13 Jan 2022 20:40:53 +0530
Subject: [PATCH] Removed KeyError(not fully) only ones with lowcapital eg:
poland will trigger keyerror but Poland will not so make first letter upper
---
api/main.py | 14 ++++++++++----
merged.py | 12 +++++++-----
2 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/api/main.py b/api/main.py
index 925d947..4184f5e 100644
--- a/api/main.py
+++ b/api/main.py
@@ -1,6 +1,7 @@
import json
from fastapi import FastAPI, Request
import uvicorn
+
app = FastAPI()
@app.get("/")
@@ -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.'
}
@@ -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")
@@ -44,5 +51,4 @@ def run():
uvicorn.run(app, host='0.0.0.0', port=8080)
-covid19data().start()
-Thread(target=run).start()
\ No newline at end of file
+covid19data().start()
\ No newline at end of file
diff --git a/merged.py b/merged.py
index ac7e4f5..3b1dabd 100644
--- a/merged.py
+++ b/merged.py
@@ -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)
@@ -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()
@@ -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.'
}
@@ -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")