-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
47 lines (36 loc) · 1.24 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
from flask import Flask, render_template, request
from urllib import request as r
def country_summary(country):
html = r.urlopen("https://api.covid19api.com/summary")
data = html.read()
data_as_dict = eval(data.decode("UTF-8"))
x = []
found = False
for countries in data_as_dict["Countries"]:
if countries['Country'] == country:
for info in countries:
country_data = info, countries[info]
x.append(country_data)
found = True
if found == False:
return "Country not found 🙁"
return list(x[4:11])
app = Flask(__name__)
@app.route('/') # , methods=['GET','POST']
def index():
return render_template('index.html')
@app.route('/', methods=['POST'])
def getValue():
country = request.form['country']
result = country_summary(country)
final_data = ''
try:
for (stat, num) in result:
last_but_before_final_data = "{}: {},\n".format(stat, num)
final_data += (last_but_before_final_data)
except:
if result == "Country not found 🙁":
final_data = "Country not found 🙁"
return render_template("index.html", r=final_data)
if __name__ == "__main__""":
app.run(debug=True)