You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
187 lines
6.1 KiB
187 lines
6.1 KiB
from flask import Flask,request,redirect
|
|
import time
|
|
from flask_sqlalchemy import SQLAlchemy
|
|
from flask import render_template
|
|
from flask import Flask as _Flask
|
|
from flask.json import JSONEncoder as _JSONEncoder
|
|
class JSONEncoder(_JSONEncoder):
|
|
def default(self, o):
|
|
import decimal
|
|
if isinstance(o, decimal.Decimal):
|
|
|
|
return float(o)
|
|
|
|
super(JSONEncoder, self).default(o)
|
|
|
|
class Flask(_Flask):
|
|
json_encoder = JSONEncoder
|
|
|
|
import utils
|
|
from flask import jsonify
|
|
app = Flask(__name__)
|
|
|
|
app.config['SQLALCHEMY_DATABASE_URI']='mysql://root:130031@127.0.0.1:3306/cov2019'
|
|
db=SQLAlchemy(app)
|
|
|
|
class Administator(db.Model):
|
|
ad_id = db.Column(db.String(32), primary_key=True)
|
|
password = db.Column(db.String(32))
|
|
|
|
class China(db.Model):
|
|
id = db.Column(db.Integer,primary_key=True,autoincrement=True)
|
|
date=db.Column(db.String(255))
|
|
province = db.Column(db.String(255))
|
|
city = db.Column(db.String(255))
|
|
current_diagnosis=db.Column(db.Integer)
|
|
cumulative_diagnosis = db.Column(db.Integer)
|
|
suspected_case = db.Column(db.Integer)
|
|
cumulative_deaths = db.Column(db.Integer)
|
|
cumulative_cure = db.Column(db.Integer)
|
|
|
|
@app.route('/')
|
|
def hello_world():
|
|
return render_template("index.html")
|
|
|
|
@app.route('/index')
|
|
def hello_world2():
|
|
return render_template("index.html")
|
|
|
|
|
|
#管理页面
|
|
@app.route("/massage_page")
|
|
def massage_page():
|
|
china_list = China.query.order_by(China.id.desc()).all()
|
|
return render_template("massage.html",china_list=china_list)
|
|
|
|
#删除数据
|
|
@app.route("/delete",methods=['GET'])
|
|
def delete():
|
|
id = request.args.get("id")
|
|
china = China.query.filter_by(id=id).first()
|
|
db.session.delete(china)
|
|
db.session.commit()
|
|
return redirect('/massage_page')
|
|
|
|
#添加页面
|
|
@app.route("/insert_page")
|
|
def insert_page():
|
|
return render_template("insert.html")
|
|
# 添加数据
|
|
@app.route("/insert",methods=['GET','POST'])
|
|
def insert():
|
|
id = request.form["id"]
|
|
province = request.form['province']
|
|
city = request.form['city']
|
|
current_diagnosis = request.form['current_diagnosis']
|
|
cumulative_diagnosis = request.form['cumulative_diagnosis']
|
|
suspected_case = request.form['suspected_case']
|
|
cumulative_deaths = request.form['cumulative_deaths']
|
|
cumulative_cure = request.form['cumulative_cure']
|
|
china = China(id=id,province=province,city=city,current_diagnosis=current_diagnosis,cumulative_diagnosis=cumulative_diagnosis,suspected_case=suspected_case,cumulative_deaths=cumulative_deaths,cumulative_cure=cumulative_cure)
|
|
db.session.add(china)
|
|
db.session.commit()
|
|
return redirect('/massage_page')
|
|
|
|
#修改页面
|
|
@app.route("/alter_page")
|
|
def alter_page():
|
|
return render_template("alter.html")
|
|
#修改操作
|
|
@app.route("/alter",methods=['GET','POST'])
|
|
def alter():
|
|
if request.method == 'GET':
|
|
id = request.args.get("id")
|
|
province = request.args.get("provincename")
|
|
city = request.args.get("cityname")
|
|
current_diagnosis = request.args.get("current_diagnosisnumber")
|
|
cumulative_diagnosis = request.args.get("cumulative_diagnosisnumber")
|
|
suspected_case = request.args.get("suspected_casenumber")
|
|
cumulative_deaths = request.args.get("cumulative_deathsnumber")
|
|
cumulative_cure = request.args.get("cumulative_curenumber")
|
|
china = China(id = id,province=province,city=city,current_diagnosis = current_diagnosis,cumulative_diagnosis = cumulative_diagnosis,suspected_case = suspected_case,cumulative_deaths = cumulative_deaths,cumulative_cure = cumulative_cure)
|
|
return render_template("alter.html",china = china)
|
|
else:
|
|
id = request.form["id"]
|
|
province = request.form['province']
|
|
cityname = request.form['city']
|
|
current_diagnosis = request.form['current_diagnosis']
|
|
cumulative_diagnosis = request.form['cumulative_diagnosis']
|
|
suspected_case = request.form['suspected_case']
|
|
cumulative_deaths = request.form['cumulative_deaths']
|
|
cumulative_cure = request.form['cumulative_cure']
|
|
china = China.query.filter_by(id = id).first()
|
|
china.province = province
|
|
china.city = cityname
|
|
china.current_diagnosis = current_diagnosis
|
|
china.cumulative_diagnosis = cumulative_diagnosis
|
|
china.suspected_case = suspected_case
|
|
china.cumulative_deaths = cumulative_deaths
|
|
china.cumulative_cure = cumulative_cure
|
|
db.session.commit()
|
|
return redirect('/massage_page')
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/login_page")
|
|
def tiaozhuan():
|
|
return render_template("login.html")
|
|
|
|
@app.route("/login",methods=['GET','POST'])
|
|
def login():
|
|
#接收用户数据
|
|
user_list = Administator.query.all()
|
|
root = request.form['ad_id']
|
|
password = request.form['password']
|
|
user = Administator(ad_id=root ,password=password)
|
|
for user1 in user_list:
|
|
if user.ad_id==user1.ad_id and user.password==user1.password:
|
|
# 将网页重定向到管理页
|
|
return redirect("/massage_page")
|
|
#返回主页
|
|
return redirect("/index")
|
|
|
|
@app.route('/m1')
|
|
def get_m1_data():
|
|
data=utils.get_m1_data()
|
|
return jsonify({"现有确诊":data[0],"累计确诊":data[1],"疑似病例":data[2],"累计死亡":data[3],"累计治愈":data[4]})
|
|
pass
|
|
|
|
@app.route('/m2')
|
|
def get_m2_data():
|
|
res=[]
|
|
for tup in utils.get_m2_data():
|
|
res.append({"name":tup[0],"value":int(tup[1])})
|
|
return jsonify({"data":res})
|
|
|
|
@app.route('/l1')
|
|
def get_l1_data():
|
|
data =utils.get_l1_data()
|
|
day,nconfirm,confirm,dead,heal =[],[],[],[],[]
|
|
for a,b,c,d,e in data:
|
|
day.append(a.strftime("%m-%d"))
|
|
nconfirm.append(b)
|
|
confirm.append(c)
|
|
dead.append(d)
|
|
heal.append(e)
|
|
return jsonify({"日期":day,"现有确诊":nconfirm,"累计确诊":confirm,"累计死亡":dead,"累计治愈":heal})
|
|
|
|
@app.route('/r1')
|
|
def get_r1_data():
|
|
data =utils.get_r1_data()
|
|
city=[]
|
|
nc=[]
|
|
for a,b in data:
|
|
city.append(a)
|
|
nc.append(b)
|
|
return jsonify({"city":city,"nc":nc})
|
|
|
|
@app.route('/time')
|
|
def get_time():
|
|
return utils.get_time()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app.run()
|