当前位置:网站首页>太帅了!我用炫酷大屏展示爬虫数据!
太帅了!我用炫酷大屏展示爬虫数据!
2022-08-02 10:10:00 【AI科技大本营】

作者 | 派森酱
来源 | Python技术
大屏有时纯粹是为了好看,领导的说法是“花花绿绿的效果不错”。尤其放到展厅里,整面墙壁都是大屏那种,色彩十分艳丽。
我尝试了一下。不是专业的前端,所以用vue模板修改,前后端分离。
后端使用fastapi,爬取的数据存入数据库。效果图如下,点击看全屏效果

下面这张是网上下载的vue大屏,我根据它来修改的
修改内容包括:
更换背景大图,形成"暗黑"星空风格
Apache ECharts官网找适合的效果图,并修改
删除词云和中间的飞行地图等,把自己的内容排版进去

数据来源
说明
这里只介绍右边的“降水量预报”。值越大,气球越大

采用scrapy爬取数据
数据爬自weather.cma.cn
定义要爬的url,降水量相加得到某地未来一天的降雨量

运行过程

爬虫脚本
参考 ssw的小型文档网站
后端接口
数据库的爬虫数据

fastapi
接口url:
http://localhost:5000/rain/
脚本:
from fastapi import FastAPI
from fastapi.responses import JSONResponse
import pymysql
app = FastAPI()
def conn_mysql(sql):
dbparam = {
'host': '127.0.0.1',
'port': 3306,
'user': 'root',
'password': '1024',
'database': 'alerts',
'charset': 'utf8'
}
conn = pymysql.connect(**dbparam)
cursor = conn.cursor()
try:
cursor.execute(sql)
res = cursor.fetchall()
except Exception as e:
print('入库失败', e)
conn.rollback()
finally:
cursor.close()
conn.close()
return res
def get_rains_from_db():
sql = 'SELECT city,rain from rains'
res = conn_mysql(sql)
return res
@app.get('/rain')
def rain():
res = get_rains_from_db()
for i in res:
city = i[0].strip()
if (city == '益阳'):
yys = i
elif (city == '永顺'):
xxz = i
elif (city == '长沙'):
css = i
elif (city == '张家界'):
zjjs = i
elif (city == '邵阳市'):
sys = i
elif (city == '株洲'):
zzs = i
elif (city == '常德'):
cds = i
elif (city == '娄底'):
ld = i
return JSONResponse({'data': {'ld': ld, 'css': css, 'sys': sys, 'yys': yys, 'zjjs': zjjs,
'xxz': xxz, 'cds': cds, 'zzs': zzs}})前端展示
vue部分目录结构
文件已上传,下载地址
.
├── public
│ └── json
│ └── 430000.json
└── src
├── api
│ ├── http.js
│ ├── index.js
│ └── options.js
├── components
│ ├── companySummary
│ │ └── rain.vue
│ └── index.js
├── main.js
├── router
│ └── index.js
└── views
└── alerts.vue文件说明
router/index.js
编写路由
const routes = [
{
path: '/alerts',
name: 'alerts',
component: () => import('@/views/alerts.vue'),
meta: {
title: '告警'
}
},
]main.js
导入router/index.js中的路由
导入components/index.js中定义的组件,方便其它文件引用。如 在alerts.vue中写上
<rain />即可引用
import Vue from 'vue'
import router from './router'
import Vcomp from './components/index' //
Vue.use(Vcomp)components/index.js
组件在这个文件进行汇总
import rain from './companySummary/rain' //区域雨量
const components = {
rain, //指components/companySummary/rain.vue
}
const Vcomp = {
...components,
install
};
export default Vcompcomponents/companySummary/rain.vue
import {mapOptions} from '@/api/options.js'
export default {
name: 'rain',
}views/alerts.vue
这里引用rain.vue组件
...省略
<div class="panel">
<h2>20小时降水量预报</h2>
<rain />
<div class="panel-footer"></div>
</div>
...省略api/index.js
向fastapi接口发送请求
export const rainInfo = (params) => {
return axios.get('http://localhost:5000/rain/')
}api/options.js
向fastapi接口发送请求
mapOptions在rain.vue被引用,被apache echarts使用
$.ajax({
type: "GET",
url: "http://localhost:5000/rain/",
dataType: 'json',
async:false,
success: function (res) {
var xxx = [
{name: '娄底市', value: parseFloat(res.data.ld[1])},
{name: '长沙市', value: parseFloat(res.data.css[1])},
{name: '邵阳市', value: parseFloat(res.data.sys[1])},
{name: '益阳市', value: parseFloat(res.data.yys[1])},
{name: '张家界市', value: parseFloat(res.data.zjjs[1])},
{name: '湘西土家族苗族自治州', value: parseFloat(res.data.xxz[1])},
{name: '常德市', value: parseFloat(res.data.cds[1])},
{name: '株洲市', value: parseFloat(res.data.zzs[1])},
];
}})
export function mapOptions(mapType) {
var geoCoordMap = { //坐标数据
'娄底市':[112.008497,27.728136],
'长沙市':[112.982279,28.19409],
'邵阳市':[111.46923,27.237842],
'益阳市':[112.355042,28.570066],
'张家界市':[110.479921,29.127401],
'湘西土家族苗族自治州':[109.739735,28.314296],
'常德市':[111.691347,29.040225],
'株洲市':[113.151737,27.835806],
};
...省略
}总结
通过这次尝试,简单实现了大屏效果。条形图、折线图、飞行地图、词云等,还可以去Apache ECharts官网找资源加入到大屏。如果你对threejs很了解,甚至可以把它的3D效果加入进来
有些大屏用html编写,一大段一大段的代码让人失去修改的兴趣,相比来说vue更简洁、代码少、修改快。

往期回顾
分享
点收藏
点点赞
点在看边栏推荐
- 刷题错题录1-隐式转换与精度丢失
- R语言时间序列数据的平滑:使用KernSmooth包的dpill函数和locpoly函数对时间序列数据进行平滑以消除噪声
- matlab-day02
- 【技术分享】OSPFv3基本原理
- The love-hate relationship between C language volatile keyword, inline assembly volatile and compiler
- 行为型模式-模板方法模式
- This article takes you to understand the commonly used models and frameworks of recommender systems
- 牛客网项目2.7开发注册功能 报错This application has no explicit mapping for /error......
- Weak yen turns game consoles into "financial products" in Japan: scalpers make big profits
- 链表的实现
猜你喜欢
随机推荐
The R language uses the rollapply function in the zoo package to apply the specified function to the time series in a rolling manner and the window moves, and set the align parameter to specify that t
qq邮箱日发5万邮件群发技术(qq邮箱怎样定时发送邮件)
新“内卷”席卷科技圈,Google CEO 要求 174000 员工提高工作效率!
iNFTnews | Seeing the two sides of the metaverse, what is the true Internet and the Internet of value?
Implementation of mysql connection pool
21年毕业转行软件测试,从0收入到月薪过万,我真的很幸运...
用了TCP协议,就一定不会丢包嘛?
The heavyweights are coming!Spoilers for the highlights of the Alibaba Cloud Life Science and Intelligent Computing Summit
李航《统计学习方法》笔记之监督学习Supervised learning
行为型模式-模板方法模式
R language ggplot2 visualization: use the ggbarplot function of the ggpubr package to visualize the horizontal column chart (bar chart), use the orientation parameter to set the column chart to be tra
如何搭建威纶通触摸屏与S7-200smart之间无线PPI通信?
【OpenCV】-霍夫变换
Use compilation to realize special effects of love
如何安装dosbox(pycharm详细安装教程)
c#反射和特性
QT专题:自定义部件
ConvNeXt论文及实现
神通数据库,批量插入数据的时候失败
php组件漏洞









