其他分享
首页 > 其他分享> > 移动端+网页端全球疫情数据展示系统

移动端+网页端全球疫情数据展示系统

作者:互联网

写在前面:

本文所有代码已发布到github: web端:(https://github.com/wushenjiang/getWorldDataJava) 安卓端:(https://github.com/wushenjiang/GetWorldData),需要代码的可以自行去clone。

需求:

设计思想:

编程前准备:

爬虫代码展示:

import pymysql
import requests
import json
# 放入要爬的url
url = "https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5"
# 设置header做一个防爬机制
header = {"user-agent": "Mozilla/5.0 (Linux; Android 8.0.0; Pixel 2 XL Build/OPD1.170816.004) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Mobile Safari/537.36"}
# 获取response的json
response = requests.get(url, headers=header)
# 取得数据词典
data = json.loads(response.content.decode())
data_str = data['data']
data_json = json.loads(data_str)
# 连接数据库
db = pymysql.connect(host = '39.97.109.245', port=3306, user='root', password='abc456', db='yiqing', charset='utf8')
#使用cursor方法生成一个游标
cursor = db.cursor()
confirmed_total = 0
suspected_total = 0
dead_total = 0
healed_total = 0
# 更新时间
lastUpdateTime = data_json['lastUpdateTime']
# 取出各个国家的数据
for worldData in data_json['areaTree']:
    countryName = worldData['name']
    confirmed = worldData['total']['confirm']
    confirmed_total += confirmed
    suspected = worldData['total']['suspect']
    suspected_total += suspected
    dead = worldData['total']['dead']
    dead_total += dead
    healed = worldData['total']['heal']
    healed_total += healed
    sql = "insert into worlddata(id,countryname,confirmed,suspected,dead,healed,lastupdateTime) values({},'{}','{}','{}','{}', '{}','{}')".format(0, countryName, confirmed, suspected, dead, healed, lastUpdateTime)
    cursor.execute(sql)
    db.commit()
sql_total = "insert into worlddata(id,countryname,confirmed,suspected,dead,healed,lastupdateTime) values({},'{}','{}','{}','{}', '{}','{}')".format(0, 0, confirmed_total, suspected_total, dead_total, healed_total, lastUpdateTime)
cursor.execute(sql_total)
db.commit()

效果截图:

web端预览地址:http://39.97.109.245/getWorldData/getWorldData

APP截图:


预估时间记录日志:

PSP2.1 阶段 时间
Planning 计划 3h45m
- Estimate 估计这个任务需要多少时间 3h45m
Development 开发
- Analysis 需求分析 1h30m
- Coding Standard 代码规范 15m
- Design 具体设计 30m
- Coding 具体编码 30m
- Test 测试 1h
- Count 总计 3h45min

实际时间记录日志:

PSP2.1 阶段 时间
Development 开发
- Analysis 需求分析 2h
- Coding Standard 代码规范 15m
- Design 具体设计 30m
- Coding 具体编码 45m
- Test 测试 1h30min
- Count 总计 5h

测试用例分享:

WEB:

APP:

总结:

本次作业也算是真正的体验了一把如何开发真正的项目,从WEB开发到APP开发再到部署到服务器,整个体验了一波如何构造一个小型项目,收益很大。由于安卓开发不是很熟练,所以花费了大量时间在查找资料和各种示例代码上,因为对安卓组件的不熟悉,每做一个都要百度一下这个组件怎么使用,也是极大的浪费了时间。以后会抓紧学习安卓开发,争取做出更好的APP。WEB端方面,正在学习SSM框架,等学习完后可能会将本项目进行重构。来日方长,加油吧自己。

标签:confirmed,网页,疫情,展示,dead,healed,suspected,total,data
来源: https://www.cnblogs.com/wushenjiang/p/12516037.html