全部文件

master
lzp 5 years ago
parent 8afc1fa9fb
commit 6190c0a510

@ -0,0 +1,68 @@
from flask import Flask, render_template
from mydb import MyDB
from flask import jsonify
app = Flask(__name__)
@app.route('/hello')
def say_hello():
return '<html><body><h1>Hello World</h1></body></html>'
@app.route('/')
def hello():
return render_template('hello.html', name='Jerry')
@app.route('/province_topn_curconfirm')
def get_province_curconfirm_topn():
mydb = MyDB('localhost', 'root', 'Aa183365', 'covid19_datas')
results = mydb.get_province_curconfirm_top5() # results : []
return jsonify(pub_date=results[0][2], privinces=[x[0] for x in results], curConfirms=[x[1] for x in results])
@app.route('/country_topn_curconfirm')
def get_country_curconfirm_topn():
mydb1 = MyDB('localhost', 'root', 'Aa183365', 'covid19_datas')
results = mydb1.get_country_curconfirm_top10() # results : []
return jsonify(pub_date=results[0][2], privinces=[x[0] for x in results], curConfirms=[x[1] for x in results])
@app.route('/province_curconfirm')
def get_province_curconfirm():
mydb = MyDB('localhost', 'root', 'Aa183365', 'covid19_datas')
results = mydb.get_province_curConfirms() # results : [(), (), ...]
return jsonify(pub_date=results[0][2], provinces=[x[0] for x in results], curConfirms=[x[1] for x in results])
@app.route('/country_curconfirm')
def get_country_curconfirm():
mydb = MyDB('localhost', 'root', 'Aa183365', 'covid19_datas')
results = mydb.get_country_curConfirms() # results : [(), (), ...]
return jsonify(pub_date=results[0][2], provinces=[x[0] for x in results], curConfirms=[x[1] for x in results])
@app.route('/guangxi_curconfirm')
def get_guangxi_curconfirm():
mydb = MyDB('localhost', 'root', 'Aa183365', 'covid19_datas')
results = mydb.get_guangxi_curConfirms() # results : [(), (), ...]
return jsonify(pub_date=results[0][2], provinces=[x[0] for x in results], curConfirms=[x[1] for x in results])
@app.route('/henan_curconfirm')
def get_henan_curconfirm():
mydb = MyDB('localhost', 'root', 'Aa183365', 'covid19_datas')
results = mydb.get_henan_curConfirms() # results : [(), (), ...]
return jsonify(pub_date=results[0][2], provinces=[x[0] for x in results], curConfirms=[x[1] for x in results])
@app.route('/province_top5')
def get_province_topn():
mydb = MyDB('localhost', 'root', 'Aa183365', 'covid19_datas')
results = mydb.get_province_top5() # results : []
return jsonify(pub_date=results[0][4], privinces=[x[0] for x in results], curConfirms=[x[1] for x in results],confirmcount=[x[2] for x in results],curecount=[x[3] for x in results])
@app.route('/country_top10')
def get_country_top10():
mydb = MyDB('localhost', 'root', 'Aa183365', 'covid19_datas')
results = mydb.get_country_top10() # results : []
return jsonify(pub_date=results[0][4], privinces=[x[0] for x in results], curConfirms=[x[1] for x in results],confirmcount=[x[2] for x in results],curecount=[x[3] for x in results])
app.run()

@ -0,0 +1,280 @@
import pymysql
from datetime import datetime, timedelta
import time
class MyDB:
def __init__(self, host, user, passwd, db):
self.conn = pymysql.connect(host, user, passwd, db)
self.cursor = self.conn.cursor()
def __del__(self):
self.conn.close()
# 获取当然日期
def get_cur_date(self):
date = datetime.today()
curdate = date.strftime('%Y-%m-%d')
return curdate
# 获取前N天的日期
def get_pren_date(self, n=1):
predate = datetime.today() + timedelta(-n)
predate = predate.strftime('%Y-%m-%d')
return predate
# 获取现有确诊人数最多的5个省份
def get_province_curconfirm_top5(self):
curdate = self.get_cur_date() # 获取当天的日期
sql = "select provinceName,currentConfirmedCount,pub_date from province_daily_datas where pub_date like '%s' order by currentConfirmedCount desc limit 5" % (curdate + '%')
print('+++ sql: %s' % sql)
results = []
try:
self.cursor.execute(sql)
results = self.cursor.fetchall()
n = 1
while len(results) <= 0:
predate = self.get_pren_date(n)
sql = "select provinceName,currentConfirmedCount,pub_date from province_daily_datas where pub_date like '%s' order by currentConfirmedCount desc limit 5" % (predate + '%')
print('+++ presql: %s' % sql)
self.cursor.execute(sql)
results = self.cursor.fetchall()
n += 1
if n >= 30:
break
else:
time.sleep(1)
except Exception as e:
print(e)
#print(results)
return results
#获取当前确诊人数前十的国家
def get_country_curconfirm_top10(self):
curdate = self.get_cur_date() # 获取当天的日期
sql = "select country,curConfirm,pub_date from foreign_datas where pub_date like '%s' order by curConfirm desc limit 10" % (curdate + '%')
print('+++ sql: %s' % sql)
results = []
try:
self.cursor.execute(sql)
results = self.cursor.fetchall()
n = 1
while len(results) <= 0:
predate = self.get_pren_date(n)
sql = "select country,curConfirm,pub_date from foreign_datas where pub_date like '%s' order by curConfirm desc limit 10" % (predate + '%')
print('+++ presql: %s' % sql)
self.cursor.execute(sql)
results = self.cursor.fetchall()
n += 1
if n >= 30:
break
else:
time.sleep(1)
except Exception as e:
print(e)
# print(results)
return results
# 获取最新一天每个省份的现有确诊数量
def get_province_curConfirms(self):
curdate = self.get_cur_date() # 获取当天的日期
sql = 'select provinceshortName,currentConfirmedCount,pub_date from province_daily_datas where pub_date like "%s"' % (curdate + '%')
print('+++ sql: %s' % sql)
results = []
try:
self.cursor.execute(sql)
results = self.cursor.fetchall()
n = 1
while len(results) <= 0:
predate = self.get_pren_date(n)
sql = 'select provinceshortName,currentConfirmedCount,pub_date from province_daily_datas where pub_date like "%s"' % (predate + '%')
print('+++ sql: %s' % sql)
self.cursor.execute(sql)
results = self.cursor.fetchall()
n += 1
if n >= 15:
break
else:
time.sleep(1)
except Exception as e:
print(e)
#print(results)
return results
# 获取最新一天每个国家的现有确诊数量
def get_country_curConfirms(self):
curdate = self.get_cur_date() # 获取当天的日期
sql = 'select country,curConfirm,pub_date from foreign_datas where pub_date like "%s"' % (curdate + '%')
print('+++ sql: %s' % sql)
results = []
try:
self.cursor.execute(sql)
results = self.cursor.fetchall()
n = 1
while len(results) <= 0:
predate = self.get_pren_date(n)
sql = 'select country,curConfirm,pub_date from foreign_datas where pub_date like "%s"' % (predate + '%')
print('+++ sql: %s' % sql)
self.cursor.execute(sql)
results = self.cursor.fetchall()
n += 1
if n >= 15:
break
else:
time.sleep(1)
except Exception as e:
print(e)
#print(results)
return results
# 获取最新一天广西的现有确诊数量
def get_guangxi_curConfirms(self):
curdate = self.get_cur_date() # 获取当天的日期
sql = 'select cityName,confirmedCount,pub_date from city_daily_datas where province="广西" and pub_date like "%s"' % (curdate + '%')
print('+++ sql: %s' % sql)
results = []
try:
self.cursor.execute(sql)
results = self.cursor.fetchall()
n = 1
while len(results) <= 0:
predate = self.get_pren_date(n)
sql = 'select cityName,confirmedCount,pub_date from city_daily_datas where province="广西" and pub_date like "%s"' % (predate + '%')
print('+++ sql: %s' % sql)
self.cursor.execute(sql)
results = self.cursor.fetchall()
n += 1
if n >= 15:
break
else:
time.sleep(1)
except Exception as e:
print(e)
#print(results)
return results
# 获取最新一天河南的现有确诊数量
def get_henan_curConfirms(self):
curdate = self.get_cur_date() # 获取当天的日期
sql = 'select cityName,curedCount,pub_date from city_daily_datas where province="河南" and pub_date like "%s"' % (curdate + '%')
print('+++ sql: %s' % sql)
results = []
try:
self.cursor.execute(sql)
results = self.cursor.fetchall()
n = 1
while len(results) <= 0:
predate = self.get_pren_date(n)
sql = 'select cityName,curedCount,pub_date from city_daily_datas where province="河南" and pub_date like "%s"' % (predate + '%')
print('+++ sql: %s' % sql)
self.cursor.execute(sql)
results = self.cursor.fetchall()
n += 1
if n >= 15:
break
else:
time.sleep(1)
except Exception as e:
print(e)
#print(results)
return results
# 获取现有确诊人数最多的5个省份
def get_province_top5(self):
curdate = self.get_cur_date() # 获取当天的日期
sql = "select provinceName,currentConfirmedCount,confirmedCount,curedCount,pub_date from province_daily_datas where pub_date like '%s' order by currentConfirmedCount desc limit 5" % (curdate + '%')
print('+++ sql: %s' % sql)
results = []
try:
self.cursor.execute(sql)
results = self.cursor.fetchall()
n = 1
while len(results) <= 0:
predate = self.get_pren_date(n)
sql = "select provinceName,currentConfirmedCount,confirmedCount,curedCount,pub_date from province_daily_datas where pub_date like '%s' order by currentConfirmedCount desc limit 5" % (predate + '%')
print('+++ presql: %s' % sql)
self.cursor.execute(sql)
results = self.cursor.fetchall()
n += 1
if n >= 30:
break
else:
time.sleep(1)
except Exception as e:
print(e)
#print(results)
return results
# 获取现有确诊人数最多的10个国家的信息
def get_country_top10(self):
curdate = self.get_cur_date() # 获取当天的日期
sql = "select country,curConfirm,confirmed,crued,pub_date from foreign_datas where pub_date like '%s' order by curConfirm desc limit 10" % (curdate + '%')
print('+++ sql: %s' % sql)
results = []
try:
self.cursor.execute(sql)
results = self.cursor.fetchall()
n = 1
while len(results) <= 0:
predate = self.get_pren_date(n)
sql = "select country,curConfirm,confirmed,crued,pub_date from foreign_datas where pub_date like '%s' order by curConfirm desc limit 10" % (predate + '%')
print('+++ presql: %s' % sql)
self.cursor.execute(sql)
results = self.cursor.fetchall()
n += 1
if n >= 30:
break
else:
time.sleep(1)
except Exception as e:
print(e)
#print(results)
return results
'''
if __name__ == "__main__":
mydb = MyDB('localhost', 'root', 'Aa183365', 'covid19_datas')
results = mydb.get_province_curconfirm_top5() # results : []
print(type(results[0]))
'''

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

@ -0,0 +1,3 @@
function sayHello() {
 alert("Hello World")
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -0,0 +1,60 @@
var myCharts7 = echarts.init(document.getElementById("main7"));
var option7 = {
title: {
text: '全国各地区现有确诊人数',
subtext: '',
left: 'center',
textStyle:{
fontFamily:'微软雅黑'
}
},
tooltip: {},
xAxis: {
type: 'category',
data: [],
axisLabel:{
interval:0,//横轴信息全部显示
}
},
yAxis: {
type: 'value'
},
series: [{
name:'现有确诊病例:',
data: [],
type: 'bar',
label: { //每个柱子顶端显示数值
normal: {
show: true,
position: 'top'
}
}
}]
};
// 向后台发起请求,获取数据
$.ajax({
cache: false,
type:"GET",
url:"/province_curconfirm",
data: null,
dataType : "json",
async: false,
error: function(request) {
alert("发送请求失败!");
},
success: function(result) {
// pub_date, privinces, curConfirms
option7.title.subtext = "数据更新时间: " + result.pub_date
for(i=0; i<result.provinces.length; ++i) {
option7.xAxis.data.push(result.provinces[i])
option7.series[0].data.push(result.curConfirms[i])
}
print(result)
console.info(result)
}
});
myCharts7.setOption(option7);

@ -0,0 +1,38 @@
var myCharts10 = echarts.init(document.getElementById("main10"));
var option10 = {
xAxis: {
type: 'category',
data: []
},
yAxis: {
type: 'value'
},
series: [{
data: [],
type: 'line'
}]
};
// 向后台发起请求,获取数据
$.ajax({
cache: false,
type:"GET",
url:"/province_curconfirm",
data: null,
dataType : "json",
async: false,
error: function(request) {
alert("发送请求失败!");
},
success: function(result) {
// pub_date, privinces, curConfirms
for(i=0; i<result.provinces.length; ++i) {
option10.xAxis.data.push(result.provinces[i])
option10.series[0].data.push(result.curConfirms[i])
}
print(result)
console.info(result)
}
});
myCharts10.setOption(option10);

@ -0,0 +1,64 @@
var myCharts1 = echarts.init(document.getElementById("main1"));
var option1 = {
title: {
text: '现有确诊人数最多的五个省份',
subtext: '',
left: 'center',
textStyle:{
fontFamily:'微软雅黑'
}
},
tooltip: {
trigger: 'item',
formatter: '{a} <br/>{b} : {c} ({d}%)'
},
legend: {
type: 'scroll',
orient: 'vertical',
right: 10,
top: 20,
bottom: 20,
data: []
},
series: [
{
name: '省份',
type: 'pie',
radius: '55%',
center: ['40%', '50%'],
data: [],
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
]
};
// 向后台发起请求,获取数据
$.ajax({
cache: false,
type:"GET",
url:"/province_topn_curconfirm",
data: null,
dataType : "json",
async: false,
error: function(request) {
alert("发送请求失败!");
},
success: function(result) {
// pub_date, privinces, curConfirms
option1.title.subtext = "数据更新时间: " + result.pub_date
for(i=0; i<result.privinces.length; ++i) {
option1.legend.data.push(result.privinces[i])
option1.series[0].data.push({name:result.privinces[i], value:result.curConfirms[i]})
}
console.info(result)
}
});
myCharts1.setOption(option1);

@ -0,0 +1,141 @@
var myCharts3 = echarts.init(document.getElementById('main3'));
var option3 = {
tooltip: {
trigger: 'item',
formatter: "省份:{b}<br/>确诊:{c}"
},
textStyle: {color: '#FFFFFF'},
title:{
left: 'center',
text: '中国疫情地图(现有确诊人数)',
subtext: '数据更新时间: ',
textStyle:{
fontSize:20,
align:"center"
}
},
visualMap: {
left: 'left',
top: 'bottom',
splitNumber: 7,
pieces: [
{value: 0},
{min: 0, max: 9},
{min: 10, max: 49},
{min: 50, max: 99},
{min: 100, max: 999},
{min: 1000, max: 9999},
{min: 10000}
],
textStyle: {
color: "#B80909"
},
inRange: {
color: ["#FFFFFF", "#FFE5DB", "#FFC4B3", "#FF9985", "#F57567", "#E64546", "#B80909"]
},
outOfRange: {
color: "#FFFFFF"
},
show:true
},
geo:{
map:'china',
roam:false,//不开启缩放和平移
zoom:1.23,//视角缩放比例
label: {
normal: {
show: true,
fontSize:'11',
color: '#6C6C6C'
}
},
itemStyle: {
normal:{
borderColor: 'rgba(0, 0, 0, 0.2)'
},
emphasis:{
areaColor: '#FF0000',//鼠标悬停区域颜色
shadowOffsetX: 0,
shadowOffsetY: 0,
shadowBlur: 20,
borderWidth: 0,
shadowColor: 'rgba(255, 255, 255, 0.5)'
}
}
},
series:[{
name:'现有确诊',
type:'map',
map:'china',
geoIndex: 0,
roam: true,
label: {
normal: {
show: true,
textStyle:{
color: 'rgb(0, 0, 0)',
fontSize: 14
}
}
},
data:[
// {name:"南海诸岛",value:0},
// {name: '北京', value: 97},
// {name: '天津', value: 5},
// {name: '上海', value: 30},
// {name: '重庆', value: 2},
// {name: '河北', value: 2},
// {name: '河南', value: 1},
// {name: '云南', value: 2},
// {name: '辽宁', value: 4},
// {name: '黑龙江', value: 13},
// {name: '湖南', value: 0},
// {name: '安徽', value: 0},
// {name: '山东', value: 9},
// {name: '新疆', value: 0},
// {name: '江苏', value: 5},
// {name: '浙江', value: 15},
// {name: '江西', value: 1},
// {name: '湖北', value: 8685},
// {name: '广西', value: 3},
// {name: '甘肃', value: 40},
// {name: '山西', value: 1},
// {name: '内蒙古', value: 1},
// {name: '陕西', value: 7},
// {name: '吉林', value: 0},
// {name: '福建', value: 0},
// {name: '贵州', value: 0},
// {name: '广东', value: 49},
// {name: '青海', value: 0},
// {name: '西藏', value: 0},
// {name: '四川', value: 17},
// {name: '宁夏', value: 0},
// {name: '海南', value: 1},
// {name: '台湾', value: 54},
// {name: '香港', value: 70},
// {name: '澳门', value: 2}
]
}]
};
$.ajax({
cache: false,
url:'/province_curconfirm',
type:"GET",
dataType:'json',
async:false,
error: function(request) {
alert("发送请求失败!");
},
success: function(result) {
console.info('+++++ my_china.js')
console.info(result)
for(i=0,max=result.provinces.length; i<max; ++i) {
option3.series[0].data.push({name:result.provinces[i], value:result.curConfirms[i]})
}
option3.title.subtext = '数据更新时间: ' + result.pub_date
}
});
myCharts3.setOption(option3);

@ -0,0 +1,107 @@
var myCharts5 = echarts.init(document.getElementById('main5'));
var option5 = {
tooltip: {
trigger: 'item',
formatter: "市名:{b}<br/>累计确诊:{c}"
},
textStyle: {color: '#FFFFFF'},
title:{
left: 'center',
text: '广西疫情地图(累计确诊人数)',
subtext: '数据更新时间: ',
textStyle:{
fontSize:20,
align:"center"
}
},
visualMap: {
left: 'left',
top: 'bottom',
splitNumber: 7,
pieces: [
{value: 0},
{min: 0, max: 9},
{min: 10, max: 49},
{min: 50, max: 99},
{min: 100, max: 999},
{min: 1000, max: 9999},
{min: 10000}
],
textStyle: {
color: "#B80909"
},
inRange: {
color: ["#FFFFFF", "#FFE5DB", "#FFC4B3", "#FF9985", "#F57567", "#E64546", "#B80909"]
},
outOfRange: {
color: "#FFFFFF"
},
show:true
},
geo:{
map:'广西',
roam:false,//不开启缩放和平移
zoom:1.23,//视角缩放比例
label: {
normal: {
show: true,
fontSize:'11',
color: '#6C6C6C'
}
},
itemStyle: {
normal:{
borderColor: 'rgba(0, 0, 0, 0.2)'
},
emphasis:{
areaColor: '#FF0000',//鼠标悬停区域颜色
shadowOffsetX: 0,
shadowOffsetY: 0,
shadowBlur: 20,
borderWidth: 0,
shadowColor: 'rgba(255, 255, 255, 0.5)'
}
}
},
series:[{
name:'现有确诊',
type:'map',
map:'广西',
geoIndex: 0,
roam: true,
label: {
normal: {
show: true,
textStyle:{
color: 'rgb(0, 0, 0)',
fontSize: 14
}
}
},
data:[
]
}]
};
$.ajax({
cache: false,
url:'/guangxi_curconfirm',
type:"GET",
dataType:'json',
async:false,
error: function(request) {
alert("发送请求失败!");
},
success: function(result) {
console.info('+++++ my_guangxi.js')
console.info(result)
for(i=0,max=result.provinces.length; i<max; ++i) {
option5.series[0].data.push({name:result.provinces[i], value:result.curConfirms[i]})
}
option5.title.subtext = '数据更新时间: ' + result.pub_date
}
});
myCharts5.setOption(option5);

@ -0,0 +1,108 @@
var myCharts4 = echarts.init(document.getElementById('main4'));
var option4 = {
backgroundColor: 'rgba(0, 178, 255, 0.89)',
tooltip: {
trigger: 'item',
formatter: "国家:{b}<br/>确诊:{c}"
},
textStyle: {color: '#FFFFFF'},
title:{
left: 'center',
text: '世界疫情地图(现有确诊人数)',
subtext: '数据更新时间: ',
textStyle:{
fontSize:20,
align:"center"
}
},
visualMap: {
left: 'left',
top: 'bottom',
splitNumber: 7,
pieces: [
{value: 0},
{min: 0, max: 9},
{min: 10, max: 49},
{min: 50, max: 99},
{min: 100, max: 999},
{min: 1000, max: 9999},
{min: 10000}
],
textStyle: {
color: "#B80909"
},
inRange: {
color: ["#FFFFFF", "#FFE5DB", "#FFC4B3", "#FF9985", "#F57567", "#E64546", "#B80909"]
},
outOfRange: {
color: "#FFFFFF"
},
show:true
},
geo:{
map:'world',
roam:false,//不开启缩放和平移
zoom:1.23,//视角缩放比例
label: {
normal: {
show: true,
fontSize:'11',
color: '#6C6C6C'
}
},
itemStyle: {
normal:{
borderColor: 'rgba(0, 0, 0, 0.2)'
},
emphasis:{
areaColor: '#FF0000',//鼠标悬停区域颜色
shadowOffsetX: 0,
shadowOffsetY: 0,
shadowBlur: 20,
borderWidth: 0,
shadowColor: 'rgba(255, 255, 255, 0.5)'
}
}
},
series:[{
name:'现有确诊',
type:'map',
map:'world',
geoIndex: 0,
roam: true,
label: {
normal: {
show: true,
textStyle:{
color: 'rgb(0, 0, 0)',
fontSize: 14
}
}
},
data:[
]
}]
};
$.ajax({
cache: false,
url:'/country_curconfirm',
type:"GET",
dataType:'json',
async:false,
error: function(request) {
alert("发送请求失败!");
},
success: function(result) {
console.info('+++++ my_world.js')
console.info(result)
for(i=0,max=result.provinces.length; i<max; ++i) {
option4.series[0].data.push({name:result.provinces[i], value:result.curConfirms[i]})
}
option4.title.subtext = '数据更新时间: ' + result.pub_date
}
});
myCharts4.setOption(option4);

@ -0,0 +1,107 @@
var myCharts6 = echarts.init(document.getElementById('main6'));
var option6 = {
tooltip: {
trigger: 'item',
formatter: "市名:{b}<br/>累计治愈:{c}"
},
textStyle: {color: '#FFFFFF'},
title:{
left: 'center',
text: '中原疫情地图(累计治愈人数)',
subtext: '数据更新时间: ',
textStyle:{
fontSize:20,
align:"center"
}
},
visualMap: {
left: 'left',
top: 'bottom',
splitNumber: 7,
pieces: [
{value: 0},
{min: 0, max: 9},
{min: 10, max: 49},
{min: 50, max: 99},
{min: 100, max: 999},
{min: 1000, max: 9999},
{min: 10000}
],
textStyle: {
color: "rgba(21, 255, 0, 1)"
},
inRange: {
color: ["rgba(21, 255, 0, 0)", "rgba(21, 255, 0, 0.2)", "rgba(21, 255, 0, 0.4)", "rgba(21, 255, 0, 0.5)", "rgba(21, 255, 0, 0.6)", "rgba(21, 255, 0, 0.8)", "rgba(21, 255, 0, 1)"]
},
outOfRange: {
color: "#FFFFFF"
},
show:true
},
geo:{
map:'河南',
roam:false,//不开启缩放和平移
zoom:1.23,//视角缩放比例
label: {
normal: {
show: true,
fontSize:'11',
color: '#6C6C6C'
}
},
itemStyle: {
normal:{
borderColor: 'rgba(0, 0, 0, 0.2)'
},
emphasis:{
areaColor: 'rgba(21, 255, 0, 1)',//鼠标悬停区域颜色
shadowOffsetX: 0,
shadowOffsetY: 0,
shadowBlur: 20,
borderWidth: 0,
shadowColor: 'rgba(255, 255, 255, 0.5)'
}
}
},
series:[{
name:'现有确诊',
type:'map',
map:'河南',
geoIndex: 0,
roam: true,
label: {
normal: {
show: true,
textStyle:{
color: 'rgb(0, 0, 0)',
fontSize: 14
}
}
},
data:[
]
}]
};
$.ajax({
cache: false,
url:'/henan_curconfirm',
type:"GET",
dataType:'json',
async:false,
error: function(request) {
alert("发送请求失败!");
},
success: function(result) {
console.info('+++++ myhome.js')
console.info(result)
for(i=0,max=result.provinces.length; i<max; ++i) {
option6.series[0].data.push({name:result.provinces[i], value:result.curConfirms[i]})
}
option6.title.subtext = '数据更新时间: ' + result.pub_date
}
});
myCharts6.setOption(option6);

@ -0,0 +1,55 @@
var myCharts8 = echarts.init(document.getElementById("main8"));
var option8 = {
title: {
text: '全国各省现有确诊人数top5具体数据比较',
subtext: '',
left: 'center',
textStyle:{
color:'rgba(255, 0, 0, 0)',
fontFamily:'微软雅黑'
}
},
legend: {},
tooltip: {},
dataset: {
source: [['省份', '现存确诊', '累计确诊', '累计治愈'],
['Matcha Latte', 43.3, 85.8, 93.7],
['Milk Tea', 83.1, 73.4, 55.1],
['Cheese Cocoa', 86.4, 65.2, 82.5],
['Walnut Brownie', 72.4, 53.9, 39.1],
['a', 72.4, 53.9, 39.1]]
},
xAxis: {type: 'category'},
yAxis: {
},
// Declare several bar series, each will be mapped
// to a column of dataset.source by default.
series: [
{type: 'bar'},
{type: 'bar'},
{type: 'bar'}
]
};
// 向后台发起请求,获取数据
$.ajax({
cache: false,
type:"GET",
url:"/province_top5",
data: null,
dataType : "json",
async: false,
error: function(request) {
alert("发送请求失败!");
},
success: function(result) {
option8.title.subtext = "数据更新时间: " + result.pub_date
for(i=0; i<5; ++i) {
option8.dataset.source[i+1][0]=result.privinces[i]
option8.dataset.source[i+1][1]=result.curConfirms[i]
option8.dataset.source[i+1][2]=result.confirmcount[i]
option8.dataset.source[i+1][3]=result.curecount[i]
}
console.info(result)
}
});
myCharts8.setOption(option8);

@ -0,0 +1,64 @@
var myCharts2 = echarts.init(document.getElementById("main2"));
var option2 = {
title: {
text: '现有确诊人数最多的十个国家',
subtext: '',
left: 'center',
textStyle:{
fontFamily:'微软雅黑'
}
},
tooltip: {
trigger: 'item',
formatter: '{a} <br/>{b} : {c} ({d}%)'
},
legend: {
type: 'scroll',
orient: 'vertical',
right: 10,
top: 20,
bottom: 20,
data: []
},
series: [
{
name: '国家',
type: 'pie',
radius: '55%',
center: ['40%', '50%'],
data: [],
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
]
};
// 向后台发起请求,获取数据
$.ajax({
cache: false,
type:"GET",
url:"/country_topn_curconfirm",
data: null,
dataType : "json",
async: false,
error: function(request) {
alert("发送请求失败");
},
success: function(result) {
// pub_date, privinces, curConfirms
option2.title.subtext = "数据更新时间: " + result.pub_date
for(i=0; i<result.privinces.length; ++i) {
option2.legend.data.push(result.privinces[i])
option2.series[0].data.push({name:result.privinces[i], value:result.curConfirms[i]})
}
console.info(result)
}
});
myCharts2.setOption(option2);

@ -0,0 +1,60 @@
var myCharts9 = echarts.init(document.getElementById("main9"));
var option9 = {
title: {
text: '全球现有确诊人数top5具体数据比较',
subtext: '',
left: 'center',
textStyle:{
color:'rgba(255, 0, 0, 0)',
fontFamily:'微软雅黑'
}
},
legend: {},
tooltip: {},
dataset: {
source: [['国家', '现存确诊', '累计确诊', '累计治愈'],
['Matcha Late', 43.3, 85.8, 93.7],
['Milk Te2a', 83.1, 73.4, 55.1],
['Cheese C3ocoa', 86.4, 65.2, 82.5],
['Walnut Br4ownie', 72.4, 53.9, 39.1],
['Matcha La5tte', 43.3, 85.8, 93.7],
['Milk Te7a', 83.1, 73.4, 55.1],
['Cheese C9ocoa', 86.4, 65.2, 82.5],
['Walnut Br0ownie', 72.4, 53.9, 39.1],
['Cheese Coc-oa', 86.4, 65.2, 82.5],
['a', 72.4, 53.9, 39.1]]
},
xAxis: {type: 'category'},
yAxis: {
},
// Declare several bar series, each will be mapped
// to a column of dataset.source by default.
series: [
{type: 'bar'},
{type: 'bar'},
{type: 'bar'}
]
};
// 向后台发起请求,获取数据
$.ajax({
cache: false,
type:"GET",
url:"/country_top10",
data: null,
dataType : "json",
async: false,
error: function(request) {
alert("发送请求失败!");
},
success: function(result) {
option9.title.subtext = "数据更新时间: " + result.pub_date
for(i=0; i<10; ++i) {
option9.dataset.source[i+1][0]=result.privinces[i]
option9.dataset.source[i+1][1]=result.curConfirms[i]
option9.dataset.source[i+1][2]=result.confirmcount[i]
option9.dataset.source[i+1][3]=result.curecount[i]
}
console.info(result)
}
});
myCharts9.setOption(option9);

File diff suppressed because one or more lines are too long

@ -0,0 +1,32 @@
<!doctype html>
<html>
<head>
<script type = "text/javascript" src="{{ url_for('static', filename='hello.js') }}"></script>
<script type = "text/javascript" src="{{ url_for('static', filename='echarts.js') }}"></script>
<script type = "text/javascript" src="{{ url_for('static', filename='jquery-3.5.1.min.js') }}"></script>
<script type = "text/javascript" src="{{ url_for('static', filename='china.js') }}"></script>
<script type = "text/javascript" src="{{ url_for('static', filename='worldZH.js') }}"></script>
<script type = "text/javascript" src="{{ url_for('static', filename='guangxi.js') }}"></script>
<script type = "text/javascript" src="{{ url_for('static', filename='henan.js') }}"></script>
</head>
 <body>
<div id="main2" style="width:100%;height: 800px;"></div>
<div id="main9" style="width:100%;height: 800px;"></div>
<div id="main1" style="width:100%;height: 800px;"></div>
<div id="main8" style="width:100%;height: 800px;"></div>
<div id="main7" style="width:100%;height: 800px;"></div>
<div id="main4" style="width:100%;height: 800px;"></div>
<div id="main3" style="width:100%;height: 600px;"></div>
<div id="main5" style="width:100%;height: 800px;"></div>
<div id="main6" style="width:100%;height: 800px;"></div>
<script src="../static/js/third_bar.js"></script>
<script src="../static/js/fisrt_pie.js"></script>
<script src="../static/js/second_pie.js"></script>
<script src="../static/js/my_china.js"></script>
<script src="../static/js/my_world.js"></script>
<script src="../static/js/my_guangxi.js"></script>
<script src="../static/js/myhome.js"></script>
<script src="../static/js/first_bar.js"></script>
<script src="../static/js/second_bar.js"></script>
 </body>
</html>

@ -0,0 +1,393 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2020-08-18 19:03:48\n",
"爬取中+1\n",
"爬取中+2\n",
"爬取中+3\n",
"爬取中+4\n",
"爬取中+5\n",
"爬取中+6\n",
"爬取中+7\n",
"爬取中+8\n",
"爬取中+9\n",
"爬取中+10\n",
"爬取中+11\n",
"爬取中+12\n",
"爬取中+13\n",
"爬取中+14\n",
"爬取中+15\n",
"爬取中+16\n",
"爬取中+17\n",
"爬取中+18\n",
"爬取中+19\n",
"爬取中+20\n",
"爬取中+21\n",
"爬取中+22\n",
"爬取中+23\n",
"爬取中+24\n",
"爬取中+25\n",
"爬取中+26\n",
"爬取中+27\n",
"爬取中+28\n",
"爬取中+29\n",
"爬取中+30\n",
"爬取中+31\n",
"爬取中+32\n",
"爬取中+33\n",
"爬取中+34\n",
"国内数据上传完毕\n",
"爬取中+35\n",
"爬取中+36\n",
"爬取中+37\n",
"爬取中+38\n",
"爬取中+39\n",
"爬取中+40\n",
"爬取中+41\n",
"爬取中+42\n",
"爬取中+43\n",
"爬取中+44\n",
"爬取中+45\n",
"爬取中+46\n",
"爬取中+47\n",
"爬取中+48\n",
"爬取中+49\n",
"爬取中+50\n",
"爬取中+51\n",
"爬取中+52\n",
"爬取中+53\n",
"爬取中+54\n",
"爬取中+55\n",
"爬取中+56\n",
"爬取中+57\n",
"爬取中+58\n",
"爬取中+59\n",
"爬取中+60\n",
"爬取中+61\n",
"爬取中+62\n",
"爬取中+63\n",
"爬取中+64\n",
"爬取中+65\n",
"爬取中+66\n",
"爬取中+67\n",
"爬取中+68\n",
"爬取中+69\n",
"爬取中+70\n",
"爬取中+71\n",
"爬取中+72\n",
"爬取中+73\n",
"爬取中+74\n",
"爬取中+75\n",
"爬取中+76\n",
"爬取中+77\n",
"爬取中+78\n",
"爬取中+79\n",
"爬取中+80\n",
"爬取中+81\n",
"爬取中+82\n",
"爬取中+83\n",
"爬取中+84\n",
"爬取中+85\n",
"爬取中+86\n",
"爬取中+87\n",
"爬取中+88\n",
"爬取中+89\n",
"爬取中+90\n",
"爬取中+91\n",
"爬取中+92\n",
"爬取中+93\n",
"爬取中+94\n",
"爬取中+95\n",
"爬取中+96\n",
"爬取中+97\n",
"爬取中+98\n",
"爬取中+99\n",
"爬取中+100\n",
"爬取中+101\n",
"爬取中+102\n",
"爬取中+103\n",
"爬取中+104\n",
"爬取中+105\n",
"爬取中+106\n",
"爬取中+107\n",
"爬取中+108\n",
"爬取中+109\n",
"爬取中+110\n",
"爬取中+111\n",
"爬取中+112\n",
"爬取中+113\n",
"爬取中+114\n",
"爬取中+115\n",
"爬取中+116\n",
"爬取中+117\n",
"爬取中+118\n",
"爬取中+119\n",
"爬取中+120\n",
"爬取中+121\n",
"爬取中+122\n",
"爬取中+123\n",
"爬取中+124\n",
"爬取中+125\n",
"爬取中+126\n",
"爬取中+127\n",
"爬取中+128\n",
"爬取中+129\n",
"爬取中+130\n",
"爬取中+131\n",
"爬取中+132\n",
"爬取中+133\n",
"爬取中+134\n",
"爬取中+135\n",
"爬取中+136\n",
"爬取中+137\n",
"爬取中+138\n",
"爬取中+139\n",
"爬取中+140\n",
"爬取中+141\n",
"爬取中+142\n",
"爬取中+143\n",
"爬取中+144\n",
"爬取中+145\n",
"爬取中+146\n",
"爬取中+147\n",
"爬取中+148\n",
"爬取中+149\n",
"爬取中+150\n",
"爬取中+151\n",
"爬取中+152\n",
"爬取中+153\n",
"爬取中+154\n",
"爬取中+155\n",
"爬取中+156\n",
"爬取中+157\n",
"爬取中+158\n",
"爬取中+159\n",
"爬取中+160\n",
"爬取中+161\n",
"爬取中+162\n",
"爬取中+163\n",
"爬取中+164\n",
"爬取中+165\n",
"爬取中+166\n",
"爬取中+167\n",
"爬取中+168\n",
"爬取中+169\n",
"爬取中+170\n",
"爬取中+171\n",
"爬取中+172\n",
"爬取中+173\n",
"爬取中+174\n",
"爬取中+175\n",
"爬取中+176\n",
"爬取中+177\n",
"爬取中+178\n",
"爬取中+179\n",
"爬取中+180\n",
"爬取中+181\n",
"爬取中+182\n",
"爬取中+183\n",
"爬取中+184\n",
"爬取中+185\n",
"爬取中+186\n",
"爬取中+187\n",
"爬取中+188\n",
"爬取中+189\n",
"爬取中+190\n",
"爬取中+191\n",
"爬取中+192\n",
"爬取中+193\n",
"爬取中+194\n",
"爬取中+195\n",
"爬取中+196\n",
"爬取中+197\n",
"爬取中+198\n",
"爬取中+199\n",
"爬取中+200\n",
"爬取中+201\n",
"爬取中+202\n",
"爬取中+203\n",
"爬取中+204\n",
"爬取中+205\n",
"爬取中+206\n",
"爬取中+207\n",
"爬取中+208\n",
"爬取中+209\n",
"爬取中+210\n",
"爬取中+211\n",
"爬取中+212\n",
"爬取中+213\n",
"爬取中+214\n",
"爬取中+215\n",
"爬取中+216\n",
"爬取中+217\n",
"爬取中+218\n",
"爬取中+219\n",
"爬取中+220\n",
"爬取中+221\n",
"爬取中+222\n",
"爬取中+223\n",
"爬取中+224\n",
"爬取中+225\n",
"爬取中+226\n",
"爬取中+227\n",
"爬取中+228\n",
"爬取中+229\n",
"爬取中+230\n",
"爬取中+231\n",
"爬取中+232\n",
"爬取中+233\n",
"爬取中+234\n",
"爬取中+235\n",
"爬取中+236\n",
"爬取中+237\n",
"爬取中+238\n",
"爬取中+239\n",
"爬取中+240\n",
"爬取中+241\n",
"爬取中+242\n",
"爬取中+243\n",
"爬取中+244\n",
"爬取中+245\n",
"爬取中+246\n",
"爬取中+247\n",
"爬取中+248\n",
"爬取成功\n"
]
}
],
"source": [
"import requests\n",
"from bs4 import BeautifulSoup\n",
"import re\n",
"import json\n",
"import pymysql\n",
"import time\n",
"\n",
"\n",
"\n",
"# 发送get请求获得目标服务器相应\n",
"response =requests.get('https://ncov.dxy.cn/ncovh5/view/pneumonia')\n",
"# 解码\n",
"html = response.content.decode('utf-8')\n",
"# 构建soup对象\n",
"soup = BeautifulSoup(html, 'html.parser')\n",
"# 查找指定标签\n",
"tag = soup.find('script', attrs={'id':\"getAreaStat\"})\n",
"tag1 = soup.find('script', attrs= {'id':\"getListByCountryTypeService2true\"})\n",
"# 转换为字符串\n",
"tagstr = str(tag)\n",
"tagstr1 = str(tag1)\n",
"# 使用正则表达式查找所有内容, results为列表类型\n",
"results = re.findall(r'\\{\"provinceName\".*?\"cities\".*?\\]\\}',tagstr)\n",
"results1 = re.findall(r'(\\{\"id\".*?\"showRank\".*?\\})', tagstr1)\n",
"\n",
"\n",
"#提取数据更新时间\n",
"ttag = soup.find('script', attrs={'id':\"getListByCountryTypeService2true\"})\n",
"ttagstr = str(ttag)\n",
"tresults = re.findall(r'\\{\"id\".*?\"showRank\":true\\}',ttagstr)\n",
"tstr = tresults[0]\n",
"jststr = json.loads(tstr)\n",
"ts = jststr['modifyTime']\n",
"ts = float(ts)/1000\n",
"localt = time.localtime(ts)\n",
"pub_date = time.strftime(\"%Y-%m-%d %H:%M:%S\", localt)\n",
"\n",
"print(pub_date)\n",
"#打开数据库连接\n",
"db = pymysql.connect('localhost', 'root', 'Aa183365', 'covid19_datas')\n",
"#创建cursor对象\n",
"cursor = db.cursor()\n",
"#SQL语句\n",
"Psql = 'insert into province_daily_datas(provinceName,provinceShortName,currentConfirmedCount,confirmedCount,suspectedCount,curedCount,deadCount,pub_date) values(%s, %s, %s, %s, %s, %s, %s, %s)'\n",
"Csql = 'insert into city_daily_datas(cityName,currentConfirmedCount,confirmedCount,suspectedCount,curedCount,deadCount,province,pub_date) values(%s, %s, %s, %s, %s, %s, %s, %s)'\n",
"Fsql='insert into foreign_datas(country,curConfirm,died,confirmed,crued,pub_date)values(%s,%s,%s,%s,%s,%s)'\n",
"count = 1\n",
"# 解析内容,提取各个省份以及该省份的各个地市疫情数据并存入数据库\n",
"cursor.execute('truncate table province_daily_datas')\n",
"cursor.execute('truncate table city_daily_datas')\n",
"cursor.execute('truncate table foreign_datas')\n",
"for item in results:\n",
" print(\"爬取中+%d\" % count)\n",
" count+=1\n",
" item = json.loads(item)\n",
" provinceName = item['provinceName']\n",
" provinceShortName = item['provinceShortName']\n",
" currentConfirmedCount = int(item['currentConfirmedCount'])\n",
" confirmedCount = int(item['confirmedCount'])\n",
" suspectedCount = int(item['suspectedCount'])\n",
" curedCount = int(item['curedCount'])\n",
" deadCount = int(item['deadCount'])\n",
" cities=item['cities']\n",
" \n",
" cursor.execute(Psql, (provinceName,provinceShortName,currentConfirmedCount,confirmedCount,suspectedCount,curedCount,deadCount,pub_date))\n",
" db.commit()\n",
" \n",
" for city in cities:\n",
" cityName = city['cityName']\n",
" currentConfirmedCount =int(city['currentConfirmedCount'])\n",
" confirmedCount = int(city['confirmedCount'])\n",
" suspectedCount = int(city['suspectedCount'])\n",
" curedCount = int(city['curedCount'])\n",
" deadCount = int(city['deadCount'])\n",
" province = item['provinceShortName']\n",
" \n",
" cursor.execute(Csql, (cityName,currentConfirmedCount,confirmedCount,suspectedCount,curedCount,deadCount,province,pub_date))\n",
" db.commit()\n",
"print('国内数据上传完毕')\n",
"\n",
"#存取各个国家的疫情情况\n",
"for item1 in results1:\n",
" print(\"爬取中+%d\" % count)\n",
" count+=1\n",
" item1 = json.loads(item1)\n",
" country = item1['provinceName']\n",
" curConfirm = int(item1['currentConfirmedCount'])\n",
" died = int(item1['deadCount'])\n",
" confirmed = int(item1['confirmedCount'])\n",
" crued = int(item1['curedCount'])\n",
"\n",
" cursor.execute(Fsql, (country,curConfirm,died,confirmed,crued,pub_date))\n",
" db.commit()\n",
"db.close()\n",
"print(\"爬取成功\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading…
Cancel
Save