-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
114 lines (102 loc) · 5.11 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
from flask import Flask,render_template,request,jsonify
import requests
app = Flask(__name__, template_folder='template')
@app.route("/",methods=["GET"])
def index():
res=requests.get('https://disease.sh/v3/covid-19/all?yesterday=true')
data=res.json()
cases="{:,}".format(data['cases'])
deaths="{:,}".format(data['deaths'])
todaycases="{:,}".format(data['todayCases'])
todaydeaths="{:,}".format(data['todayDeaths'])
todayrecovered="{:,}".format(data['todayRecovered'])
activecases="{:,}".format(data['active'])
recovered="{:,}".format(data['recovered'])
critical="{:,}".format(data['critical'])
mild="{:,}".format(data['active']-data['critical'])
outcome="{:,}".format(data['recovered']+data['deaths'])
return render_template("index.html",todayrecovered=todayrecovered,outcome=outcome,mild=mild,critical=critical,data=data,cases=cases,deaths=deaths,todaycases=todaycases,todaydeaths=todaydeaths,activecases=activecases,recovered=recovered)
@app.route("/Allcountries",methods=["GET","POST"])
def Allcountries():
res=requests.get('https://disease.sh/v3/covid-19/countries?yesterday=true&sort')
datas=res.json()
return render_template("Allcountries.html",datas=datas)
@app.route("/scountries",methods=["GET","POST"])
def scountries():
country=''
country=request.form.get("name")
res=requests.get('https://disease.sh/v3/covid-19/countries/'+country+'?yesterday=true')
data=res.json()
country=data['country']
if res.status_code!=200:
return render_template("error.html")
else:
country=country.upper()
cases="{:,}".format(data['cases'])
deaths="{:,}".format(data['deaths'])
todaycases="{:,}".format(data['todayCases'])
todaydeaths="{:,}".format(data['todayDeaths'])
todayrecovered="{:,}".format(data['todayRecovered'])
activecases="{:,}".format(data['active'])
recovered="{:,}".format(data['recovered'])
critical="{:,}".format(data['critical'])
mild="{:,}".format(data['active']-data['critical'])
outcome="{:,}".format(data['recovered']+data['deaths'])
return render_template("country.html",country=country,todayrecovered=todayrecovered,outcome=outcome,mild=mild,critical=critical,data=data,cases=cases,deaths=deaths,todaycases=todaycases,todaydeaths=todaydeaths,activecases=activecases,recovered=recovered)
@app.route("/api/world",methods=["GET"])
def API_index():
res=requests.get('https://disease.sh/v3/covid-19/all?yesterday=true')
data=res.json()
new_data={}
new_data['cases']="{:,}".format(data['cases'])
new_data['deaths']="{:,}".format(data['deaths'])
new_data['todayCases']="{:,}".format(data['todayCases'])
new_data['todayDeaths']="{:,}".format(data['todayDeaths'])
new_data['todayRecovered']="{:,}".format(data['todayRecovered'])
new_data['active']="{:,}".format(data['active'])
new_data['recovered']="{:,}".format(data['recovered'])
new_data['critical']="{:,}".format(data['critical'])
new_data['mild']="{:,}".format(data['active']-data['critical'])
new_data['outcome']="{:,}".format(data['recovered']+data['deaths'])
return jsonify(new_data)
@app.route("/api/allcountries",methods=["GET","POST"])
def API_Allcountries():
res=requests.get('https://disease.sh/v3/covid-19/countries?yesterday=true&sort')
data=res.json()
return jsonify(data)
@app.route("/api/scountries/<country>",methods=["GET","POST"])
def API_scountries(country):
res=requests.get('https://disease.sh/v3/covid-19/countries/'+country+'?yesterday=true')
data=res.json()
country=data['country']
if res.status_code!=200:
return render_template("error.html")
else:
new_data={}
new_data['country']=country.upper()
new_data['cases']="{:,}".format(data['cases'])
new_data['deaths']="{:,}".format(data['deaths'])
new_data['todayCases']="{:,}".format(data['todayCases'])
new_data['todayDeaths']="{:,}".format(data['todayDeaths'])
new_data['todayRecovered']="{:,}".format(data['todayRecovered'])
new_data['active']="{:,}".format(data['active'])
new_data['recovered']="{:,}".format(data['recovered'])
new_data['critical']="{:,}".format(data['critical'])
new_data['mild']="{:,}".format(data['active']-data['critical'])
new_data['outcome']="{:,}".format(data['recovered']+data['deaths'])
return jsonify(new_data)
@app.route("/api/vaccination",methods=["GET","POST"])
def API_vacination():
res=requests.get('https://disease.sh/v3/covid-19/vaccine/coverage/countries?lastdays=30&fullData=false')
data=res.json()
return jsonify(data)
@app.route('/api/vaccination/<country>',methods=["GET","POST"])
def API_single_vacination(country):
res=requests.get('https://disease.sh/v3/covid-19/vaccine/coverage/countries/'+country+'?lastdays=30&fullData=false')
data=res.json()
return jsonify(data)
@app.errorhandler(500)
def page_not_found():
return render_template("error.html")
if __name__ == "__main__":
app.run(debug=False)