Python Flask定时调度疫情大数据爬取全栈项目实战使用-18可视化大屏右侧模板制作

python-flask xuhss 1553℃ 0评论

Python Flask定时调度疫情大数据爬取全栈项目实战使用-18可视化大屏右侧模板制作## 可视化大屏模板制作

最终的效果

1819fd05e3aea5392d4ef0477361ca41 - Python Flask定时调度疫情大数据爬取全栈项目实战使用-18可视化大屏右侧模板制作

复制柱状图option

2edbe66c7bb85c5adf680058f52fb86e - Python Flask定时调度疫情大数据爬取全栈项目实战使用-18可视化大屏右侧模板制作

main.html导入js文件:

7f8080641e63edd010a16c6ac3e5d469 - Python Flask定时调度疫情大数据爬取全栈项目实战使用-18可视化大屏右侧模板制作

utils.py添加数据库查询操作:

def get_r1_data():
    sql = 'select city,confirm from ' \
          '(select city,confirm from details ' \
          'where update_time=(select update_time from details order by update_time desc limit 1) ' \
          'and province not in ("湖北","北京","上海","天津","重庆","香港","台湾") ' \
          'union all ' \
          'select province as city,sum(confirm) as confirm from details ' \
          'where update_time=(select update_time from details order by update_time desc limit 1) ' \
          'and province in ("北京","上海","天津","重庆","香港","台湾") group by province) as a ' \
          'order by confirm desc limit 5'
    res = query(sql)
    return res

def get_r2_data():
    sql = "select content from hotsearch order by id desc limit 20"
    res = query(sql)
    return res

app.py定义路由:

@app.route('/r1')
def get_r1_data():
    data = utils.get_r1_data()
    city = []
    confirm = []
    for k,v in data:
        city.append(k)
        confirm.append(int(v))
    return jsonify({"city": city,"confirm": confirm})

@app.route('/r2')
def get_r2_data():
    data = utils.get_r2_data()
    d = []
    for i in data:
        k = i[0].rstrip(string.digits)
        #v = i[0][len(k):]
        v = '1000'
        ks = extract_tags(k)
        for j in ks:
            if not j.isdigit():
                d.append({"name": j,"value": v})
    return jsonify({"kws": d})

controler.js中定义ajax回调

function get_r1_data() {
    $.ajax({
        url:"/r1",
        success: function(data) {
            option_right1.xAxis.data = data.city
            option_right1.series[0].data = data.confirm
            ec_right1.setOption(option_right1)
        },
        error: function(xhr, type, errorThrown) {

        }
    })
}

function get_r2_data() {
    $.ajax({
        url:"/r2",
        success: function(data) {
            option_right2.series[0].data = data.kws
            ec_right2.setOption(option_right2)
        },
        error: function(xhr, type, errorThrown) {

        }
    })
}

词云图需要引入echart-worldcloud.js:

2b7cc2e06463f3b808b8c09dd06c06e1 - Python Flask定时调度疫情大数据爬取全栈项目实战使用-18可视化大屏右侧模板制作

js文件可以到官网的进行下载:

https://echarts.apache.org/zh/download-extension.html

6ab57d2d5b0ee70f1652466f49744ad9 - Python Flask定时调度疫情大数据爬取全栈项目实战使用-18可视化大屏右侧模板制作

安装Jieba分词

pip install jieba

b5134be650280cfa634a68710d323e70 - Python Flask定时调度疫情大数据爬取全栈项目实战使用-18可视化大屏右侧模板制作

代码中使用这个jieba库

c6db7fbb97941fe86e2f48b483be94b0 - Python Flask定时调度疫情大数据爬取全栈项目实战使用-18可视化大屏右侧模板制作

from jieba.analyse import extract_tags
import string

词云图的option接受的是这个:

cfc448b6d41a1541acfa3e1da1a9e424 - Python Flask定时调度疫情大数据爬取全栈项目实战使用-18可视化大屏右侧模板制作

转载请注明:xuhss » Python Flask定时调度疫情大数据爬取全栈项目实战使用-18可视化大屏右侧模板制作

喜欢 (0)

您必须 登录 才能发表评论!