全世界疫情實時查詢系統(第三階段)


 

實現思路:

    使用Android Studio連接MySQL數據庫獲取數據;

    編寫工具類實現數據提取;

    頁面數據綁定,進行數據的展示;

    使用python爬取全球疫情的數據;

import requests
import time, json
import sys;
import pymysql

def get_wangyi_request():
    url = 'https://c.m.163.com/ug/api/wuhan/app/data/list-total'

    headers = {
        'accept': '*/*',
        'accept-encoding': 'gzip,deflate,br',
        'accept-language': 'en-US,en;q=0.9,zh-CN;q = 0.8,zh;q = 0.7',
        'origin': 'https://wp.m.163.com',
        'referer': 'https://wp.m.163.com/',
        'sec-fetch-dest': 'empty',
        'sec-fetch-mode': 'cors',
        'sec-fetch-site': 'same-ite',
        'user-agent': 'Mozilla/5.0(WindowsNT10.0;Win64;x64) AppleWebKit/37.36 (KHTML, likeGecko) Chrome/82.0.4056.0 Safari/537.36 Edg/82.0.432.3'
    }

    result = requests.get(url, headers=headers)
    return result


def print_mess1(string: str, dict1total: dict):
    sys.stdout.write(string + '確診: ' + str(dict1total['confirm'] if dict1total['confirm'] != None else 0))
    sys.stdout.write(' ')
    sys.stdout.write(string + '疑似: ' + str(dict1total['suspect'] if dict1total['suspect'] != None else 0))
    sys.stdout.write(' ')
    sys.stdout.write(string + '治愈: ' + str(dict1total['heal'] if dict1total['heal'] != None else 0))
    sys.stdout.write(' ')
    sys.stdout.write(string + '死亡: ' + str(dict1total['dead'] if dict1total['dead'] != None else 0))


if __name__ == '__main__':
    result = get_wangyi_request()

    json_str = json.loads(result.text)['data']
    # print(json_str.keys())
    # dict_keys(['chinaTotal', 'chinaDayList', 'lastUpdateTime', 'areaTree'])

    print(json_str['lastUpdateTime'])
    countryname_list = json_str['areaTree']
    # 每個省份包含如下的鍵
    # dict_keys(['today', 'total', 'extData', 'name', 'id', 'lastUpdateTime', 'children'])

    conn = pymysql.connect(
        host='localhost',  # 我的IP地址
        port=3306,  # 不是字符串不需要加引號。
        user='root',
        password='101032',
        db='test',
        charset='utf8'
    )

    cursor = conn.cursor()  # 獲取一個光標
    confirmed_total = 0
    suspected_total = 0
    dead_total = 0
    healed_total = 0
    id = 0;
    for dict in countryname_list:
        sql = 'insert into yiqing_world (countryname,confirmed,suspected,dead,healed,lastUpdateTime,id) values (%s,%s,%s,%s,%s,%s,%s);'
        countryname = dict['name']

        confirmed = dict['total']['confirm']
        confirmed_total += confirmed
        suspected = dict['total']['suspect']
        suspected_total += suspected
        healed = dict['total']['heal']
        dead_total += healed
        dead = dict['total']['dead']
        dead_total += dead
        lastUpdateTime = dict['lastUpdateTime']
        id=id+1
        sys.stdout.write( dict['name'] + '  ')
        cursor.execute(sql, [countryname,confirmed,suspected,dead,healed,lastUpdateTime,id])
    print()

    conn.commit()


    cursor.close()
    conn.close()

 

 

 

項目計划總結表:

日期 編程 完善程序 測試程序 參考資料 日總結
3.17 16:00---17:30      1.5 1.5
3.18  14:00---17:00      1.5 0.5
3.19 14:00---15:30      0.5

 0.5

3.20 20:00---22:00        0.5
3.21 7:00---11:30 14:30---17:00 18:00---21:00 1.5 0.5

 

時間記錄總結:

日期 開始 結束 中斷時間 凈時間 活動 備注
3.17 16:00 17:30 1.5 查閱資料、構思  
3.18 14:00 17:30 2.5 修改與測試、查閱資料  
3.19 14:00 15:30 1.5 修改與測試、查閱資料  
3.20 20:00 22:00 2 修改與測試、查閱資料  
3.21 7:00 11:30 0.5 4 修改與測試、查閱資料  
  14:30 17:00 0.5 2 修改與測試、查閱資料  
  18:00 21:00 0.5 2.5 修改與測試、查閱資料  

缺陷記錄表:

日期 編號 類型 引入 排除 修復 修復時間
3.17 1 程序 編程 編譯  構思思路、查閱資料  
3.18 2 程序 編程 編譯   1小時
3.19 3 程序 編程 編譯   2小時
3.20 4 程序 編程 編譯 獲取不到數據 3小時

3.21 5 程序 編程 編譯 數據頁面綁定 1小時

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM