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.

126 lines
3.2 KiB

from flask import Flask,request,redirect
from flask import render_template
import spider as sp
import contrl as co
from pymysql import *
from flask_sqlalchemy import SQLAlchemy
from flask import jsonify
import json
app = Flask(__name__)
#设置数据库连接
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:759521@127.0.0.1:3306/FeiYan'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS']=True
db = SQLAlchemy(app)
class rumor(db.Model):
id=db.Column(db.Integer, primary_key=True,autoincrement=True)
neirong=db.Column(db.String(255))
lunduan=db.Column(db.String(255))
zhengwen=db.Column(db.String(255))
bool=db.Column(db.Boolean)
class city(db.Model):
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
province_name=db.Column(db.String(255))
name=db.Column(db.String(255))
now_confirm=db.Column(db.Integer)
confirm=db.Column(db.Integer)
dead=db.Column(db.Integer)
class hospital(db.Model):
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
hos_name=db.Column(db.String(255))
location=db.Column(db.String(255))
city_name=db.Column(db.String(255))
shuxing=db.Column(db.String(255))
class country(db.Model):
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
name=db.Column(db.String(255))
now_confirm=db.Column(db.Integer)
confirm=db.Column(db.Integer)
dead=db.Column(db.Integer)
dazhou_name=db.Column(db.String(255))
def connectDB():
try:
db = connect(host='localhost', port=3306, user='root', password='759521', db='FeiYan')
print("数据库连接成功")
return db
except Exception as e:
print(e)
return
db = connectDB()
@app.route('/index')
def spider():
print('succccc')
return render_template('main.html')
@app.route('/rumor')
def rumm():
x=rumor.query.all()
return render_template('rumor.html',shuju=x)
@app.route('/hospital')
def rhosp():
x=hospital.query.all()
return render_template('hospital.html',hoss=x)
@app.route('/upcity')
def update_city():
co.update_city_table()
a="更新城市数据成功"
return a
@app.route('/upforeign')
def update_fori():
co.update_foreign_table()
a="更新国外数据成功"
return a
@app.route('/uprumor')
def update_rumor():
co.update_rumor_table()
a="更新谣言信息成功"
return a
@app.route('/uphospital')
def update_hosp():
co.update_hospital_table()
a="更新医院数据成功"
return a
@app.route('/chushihua')
def chushi():
co.chushihua()
a="初始化成功!可以用了呢~~~~记得更新数据哦"
return a
@app.route('/update-ctrl')
def up_page():
return render_template('update.html')
@app.route('/r1')
def get_r1():
data=co.get_r1_data()
print('运行中。。。')
return jsonify({"now_confirm":str(data[0]),"dead":str(data[1]),"confirm":str(data[2])})
@app.route('/c1')
def get_c1():
data=co.get_c1_data()
print('运行中。。。')
return jsonify({"now_confirm":str(data[0]),"dead":str(data[1]),"input":str(data[2]),"confirm":str(data[3])})
@app.route('/get_world',methods=["GET","POST"])
def get_world():
datalist=co.get_world_data()
print("yunxingzhene")
return jsonify(datalist)
if __name__ == '__main__':
app.run()