-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
31 lines (25 loc) · 884 Bytes
/
server.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
import flask
from flask import Flask,render_template,jsonify,Response
import requests
import bs4
app = Flask(__name__)
@app.route('/')
def indexPage():
return render_template("index.html")
@app.route('/api/recordstats',methods=['GET'])
def sendJSON():
response = requests.get("https://www.worldometers.info/coronavirus/")
content = response.content
soup = bs4.BeautifulSoup(content,'html.parser')
currentCases = soup.find_all(class_="number-table-main")
closedCases = soup.find_all(class_="number-table")
activeCases = currentCases[0].text.strip()
recoveredCases = closedCases[2].text.strip()
deaths = closedCases[3].text.strip()
return jsonify(
deathsJSON = deaths,
casesJSON = activeCases,
recoveriesJSON = recoveredCases,
)
if __name__ == "__main__":
app.run(debug=True)