1 Star 0 Fork 18

cxk10086 / 疫情实时追踪

forked from 张亚飞 / 疫情实时追踪 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

基本介绍

​ 基于 requests 模块获取腾讯提供的疫情实时数据,包含国内最新、国内历史,全球最新、全球历 史数据,以及利用 selenium 模块获取最新百度热搜榜关键词,并将获取的结构化数据存储到 MySQL 中。 通过 Flask 搭建 Web 项目,并使用 Echarts 进行数据的可视化展示,利用 ngnix 和 gunicorn 进行项目部署, 基于 crontab 的定时任务实现数据的定时爬取,确保数据的实时自动更新。

  • 技术列表:Python 网络爬虫/MySQL/Flask/Echarts/nginx/ gunicorn/crontab 定时任务
  • 在线预览:http://182.254.179.186/

数据准备

第一步:pip install -r requirements.txt
第二步:根据sql文件夹下的sql建表语句新建数据表

修改数据库配置

DATABASE = {
    'sqlite3': {
        'creator': sqlite3,
        'maxcached': 50,
        'maxconnections': 1000,
        'maxusage': 1000,
        'database': 'sqlite3.db',
        'check_same_thread': False
    },
    'mysql': {
        'creator': pymysql,
        'mincached': 5,
        'host': '127.0.0.1',
        'user': 'root',
        'passwd': '0000',
        'db': 'COVID-19',
        'port': 3306,
    }
}

更新疫情数据

python spider.py
'''
G:\programming\中大项目\COVID-19>python spider.py
2020-03-20 12:04:15.035278 获取数据完成 正在更新数据库
china history 已经是最新数据 暂时无需更新
world history 已经是最新数据 暂时无需更新
world lasted 更新完毕
china lasted 更新完毕
2020-03-20 12:05:30.468485 所有数据更新完毕

DevTools listening on ws://127.0.0.1:55447/devtools/browser/2fc040f4-08ee-4a46-b2ed-4ba1b4eccb43
[0320/120534.833:ERROR:mf_helpers.cc(14)] Error in dxva_video_decode_accelerator_win.cc on line 511
2020-03-20 12:05:37     数据更新完毕
'''

本地运行

项目部署

  • 第一步:将项目文件拷贝到服务器
  • 第二步:安装nginx和gunicorn
yun install nginx
pip install gunicorn
  • 第三步:启动gunicorn

    gunicorn -b 127.0.0.1:8080 -D manage:app
    # 重启
    pstree -ap|grep gunicorn
      |-gunicorn,18598 /usr/local/python3/bin/gunicorn -b 127.0.0.1:8080 -D manage:app
      |   `-gunicorn,18601 /usr/local/python3/bin/gunicorn -b 127.0.0.1:8080 -D manage:app
      |           |-grep,18822 --color=auto gunicorn
    kill -HUP 
  • 第四步:编辑nginx配置文件:

    vim /etc/nginx/conf.d/default.conf

    • 第五步:启动nginx

      /usr/sbin/nginx
      若已经启动: ps -A | grep nginx
      kill -9 pid1
      kill -9 pid2
    • 第六步:访问ip地址

部署定时爬虫

yum install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
下载指定版本解压之后上传到项目更目录 https://npm.taobao.org/mirrors/chromedriver/
赋予chromedirver权限  chmod +x chromedriver
crontab -e  编辑 添加
0 7-22/1 * * * python /root/web/covid-19/spider.py >> /root/web/log_spider 2>&1 &
查看日志
cat log_spider
MIT License Copyright (c) 2019 张亚飞 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

爬虫+Flask+Echarts实现疫情数据可视化及实时更新 展开 收起
Python
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Python
1
https://gitee.com/cxkaa10/COVID-19.git
git@gitee.com:cxkaa10/COVID-19.git
cxkaa10
COVID-19
疫情实时追踪
master

搜索帮助