新型冠狀肺炎疫情實時接口,新增簡易數據大屏示例

項目地址

https://github.com/leafcoder/...html

數據大屏

http://111.231.75.86/dashboardpython

介紹

本項目的數據來源爲丁香園,定時獲取疫 情數據,保存疫情數據變動狀況,以備跟蹤研究和數據圖表化展現。nginx

快速開始

請按照如下步驟完成項目的初始化和啓動。git

注意:請先修改 covid19/settings.py 中SCRAPY_CMD,設置爲 scrapy 命令完整路徑。 不然,自動更新任務將沒法正常運行github

源碼下載

能夠經過git clone直接將master分支的代碼克隆到本機使用;sql

$ cd `YOUR_PROJECT_DIR`  # 項目須要下載到的目錄
$ git@github.com:leafcoder/django-covid19.git

也能夠直接下載打包好的代碼;數據庫

$ cd `YOUR_PROJECT_DIR`  # 項目須要下載到的目錄
$ wget https://github.com/leafcoder/django-covid19/archive/<VERSION>.tar.gz  # VERSION 爲要下載的版本號
$ tar zxf <VERSION>.tar.gz

安裝依賴

啓動服務前,請先安裝項目的 python 依賴包。可使用pyenv或者virtualenvwrapper來管理python運行環境;django

$ cd django-covid19
$ pip install -r requirement.txt

若是直接經過系統自帶python運行本項目,需在命令前加上sudo;api

$ cd django-covid19
$ sudo pip install -r requirement.txt

初始化

項目默認配置是以sqlite3做爲數據庫存儲數據,若是須要修改,請自行更改covid19/settings.py中的數據庫配置; 並運行如下命令完成項目數據庫的初始化;瀏覽器

$ ./manage.py makemigrations ncovapi
$ ./manage.py migrate

項目後臺

使用後臺請先建立管理員帳號;

$ ./manage.py createsuperuser

DEBUG = False的狀況下,後臺的靜態文件將沒法使用,必須運行如下命令將靜態文件保存到對應目錄才能正常使用項目後臺;

$ ./manage.py collectstatic

定時更新

項目經過運行爬蟲程序,將每一次數據的變動保存到數據庫中;

要建立自動抓取丁香園新冠數據任務須要運行以下命令,建立定時任務;

$ ./manage.py crontab add

項目啓動

正式環境的部署建議使用nginx + uwsgi + django方案完成項目部署;簡單運行查看接口狀況,運行以下命令便可;

$ ./manage.py runserver

運行成功後,經過瀏覽器訪問http://localhost:8000/api/statistics/便可看到統計數據。

API 文檔

本系統主要是將從丁香園獲取的數據從新整合成接口返回出來。

全球疫情

Latest

獲取最新獲取到的全球總體疫情統計數據、相關文章、平常建議、推薦信息等;

接口地址:/api/statistics/latest

請求方法:GET

請求示例:

http://111.231.75.86:8000/api/statistics/latest

返回結果:

{
    "globalStatistics": {
        "confirmedCount": 2913206,
        "curedCount": 826309,
        "deadCount": 206245,
        "seriousCount": 0,
        "currentConfirmedCount": 1880652,
        "suspectedCount": 0
    },
    "domesticStatistics": {
        "confirmedCount": 84341,
        "curedCount": 78558,
        "deadCount": 4643,
        "seriousCount": 974,
        "currentConfirmedCount": 1140,
        "suspectedCount": 1636
    },
    "internationalStatistics": {
        "confirmedCount": 2828865,
        "curedCount": 747751,
        "deadCount": 201602,
        "seriousCount": 0,
        "currentConfirmedCount": 1879512,
        "suspectedCount": 4
    },
    "recommends": [
        {
            "contentType": 1,
            "countryType": 1,
            "title": "傳染病全球大流行,歷史早就告訴咱們的 5 件事",
            "recordStatus": 1,
            "linkUrl": "https://mp.weixin.qq.com/s?__biz=MjA1ODMxMDQwMQ==&mid=2657278282&idx=1&sn=ec5a88bf6cead3079f2f48f68f64aa93&chksm=4906dd247e715432a91c3c99e4d92082ffd2eb8c6ddf4355b833f597d9464aa22ad048d84d0b&token=2114569265〈=zh_CN#rd",
            "imgUrl": "https://img1.dxycdn.com/2020/0325/826/3403983726425257144-135.jpg"
        }
    ],
    "remarks": [
        "易感人羣:人羣廣泛易感。老年人及有基礎疾病者感染後病情較重,兒童及嬰幼兒也有發病",
        "潛伏期:通常爲 3~7 天,最長不超過 14 天,潛伏期內可能存在傳染性,其中無症狀病例傳染性很是罕見",
        "宿主:野生動物,可能爲中華菊頭蝠"
    ],
    "createTime": "2020-01-20T16:31:39Z",
    "generalRemark": "1. 3 月 12 日國家衛健委確診補訂遺漏 12 例確診病例(非 12 日新增),暫無具體省份信息。 2. 浙江省 12 例外省治癒暫無具體省份信息。",
    "rumors": [
        {
            "body": "近日,有人在朋友圈兜售某公司生產的新冠病毒抗體檢測試劑盒,單價 150 元,並宣稱能夠家庭自行使用。對此,北京市藥監局提示,經批准註冊的新冠病毒檢測試劑盒,均須要具有 PCR 實驗室及專用設備的醫療機構才能完成檢測,普通市民家庭不可自行使用,市民不要輕信虛假宣傳,出現相關症狀應及時就醫。",
            "mainSummary": "北京市藥監局提示:普通市民家庭不可自行使用",
            "sourceUrl": "",
            "title": "可在家使用新冠病毒試劑盒自測?",
            "summary": "",
            "score": 1000,
            "rumorType": 0
        }
    ],
    "goodsGuides": [
        {
            "contentImgUrls": [
                "https://img1.dxycdn.com/2020/0215/220/3396780175063930893-135.png",
                "https://img1.dxycdn.com/2020/0215/637/3396780181506594738-135.png",
                "https://img1.dxycdn.com/2020/0215/372/3396780187949046019-135.png"
            ],
            "recordStatus": 1,
            "categoryName": "消毒劑",
            "title": "消毒劑指南"
        }
    ],
    "modifyTime": "2020-04-27T04:33:01Z",
    "timelines": [
        {
            "sourceUrl": "http://app.cctv.com/special/cportal/detail/arti/index.html?id=ArtiL3Kf65mSxf2yQjQ7WJpZ200427&isfromapp=1",
            "pubDate": 1587958979000,
            "title": "一季度全國社會物流總額56.0萬億元 同比降低7.5%",
            "summary": "中國物流與採購聯合會今天(27日)公佈一季度物流運行數據。受新冠肺炎疫情影響,一季度社會物流總需求出現負增加。一季度,全國社會物流總額爲56.0萬億元,同比降低7.5%,與1-2月相比,降幅收窄4.3個百分點。 ",
            "pubDateStr": "9分鐘前",
            "infoSource": "央視新聞app"
        }
    ],
    "wikis": [
        {
            "linkUrl": "https://ask.dxy.com/ama/index#/disease/24677/info/0",
            "description": "這次流行的冠狀病毒爲一種新發現的冠狀病毒,國際病毒分類委員會命名爲 SARS-Cov-2。由於人羣缺乏對新型病毒株的免疫力,因此人羣廣泛易感。",
            "imgUrl": "",
            "title": "什麼是新型冠狀病毒?"
        }
    ],
    "WHOArticle": {
        "linkUrl": "https://mp.weixin.qq.com/s/6q0qMFXzoKI7MMvY7zrXUw",
        "imgUrl": "https://img1.dxycdn.com/2020/0220/196/3397701576545475720-135.jpg",
        "title": "新冠病毒會變異?口罩不夠怎麼辦?世界衛生組織的答疑來了!"
    },
    "notes": [
        "病毒:SARS-CoV-2,其致使疾病命名 COVID-19",
        "傳染源:新冠肺炎的患者。無症狀感染者也可能成爲傳染源。",
        "傳播途徑:經呼吸道飛沫、接觸傳播是主要的傳播途徑。氣溶膠傳播和消化道等傳播途徑尚待明確。"
    ]
}

List

獲取項目從啓動到當前獲取到的所有疫情統計數據,分爲全球、國內、國際三部分;

接口地址:/api/statistics/

請求方法:GET

請求示例:

http://111.231.75.86:8000/api/statistics/

返回結果:

[
    {
        "globalStatistics": {
            "confirmedCount": 2913206,
            "curedCount": 826309,
            "deadCount": 206245,
            "seriousCount": 0,
            "currentConfirmedCount": 1880652,
            "suspectedCount": 0
        },
        "domesticStatistics": {
            "confirmedCount": 84341,
            "curedCount": 78558,
            "deadCount": 4643,
            "seriousCount": 974,
            "currentConfirmedCount": 1140,
            "suspectedCount": 1636
        },
        "internationalStatistics": {
            "confirmedCount": 2828865,
            "curedCount": 747751,
            "deadCount": 201602,
            "seriousCount": 0,
            "currentConfirmedCount": 1879512,
            "suspectedCount": 4
        },
        "modifyTime": "2020-04-30T01:12:33Z",
        "createTime": "2020-01-20T16:31:39Z"
    }
]

國家疫情

Daily List(Chart Data)

根據國家名稱獲取某個國家的疫情從 2020-01-19 到目前的疫情列表數據;

接口地址:/api/countries/<COUNTRY_NAME>/daily/

請求方法:GET

示例連接:

http://111.231.75.86:8000/api/countries/美國/daily/

http://111.231.75.86:8000/api/countries/巴西/daily/

返回結果:

[
    {
        "dateId": 20200119,
        "currentConfirmedCount": 188,
        "confirmedCount": 217,
        "suspectedCount": 0,
        "curedCount": 25,
        "deadCount": 4,
        "currentConfirmedIncr": 188,
        "confirmedIncr": 217,
        "suspectedCountIncr": 0,
        "curedIncr": 25,
        "deadIncr": 4
    },
    {
        "dateId": 20200120,
        "currentConfirmedCount": 188,
        "confirmedCount": 217,
        "suspectedCount": 0,
        "curedCount": 25,
        "deadCount": 4,
        "currentConfirmedIncr": 188,
        "confirmedIncr": 217,
        "suspectedCountIncr": 0,
        "curedIncr": 25,
        "deadIncr": 4
    },
    ...
]

List

獲取各個國家的疫情統計數據;

接口地址:/api/countries/

請求方法:GET

請求參數:

參數

描述

continents

所屬大洲,可選值爲(北美洲,南美洲,非洲,歐洲,亞洲,大洋洲,南極洲);以逗號分割多個值;

countryShortCodes

國家英文縮寫,如:美國的英文縮寫爲 USA;以逗號分割多個值;

countryNames

國家中文名,如:美國、中國;以逗號分割多個值;

示例連接:

http://111.231.75.86:8000/api/countries/?continents=南美洲,北美洲&countryNames=美國,巴西

返回結果:

[
    {
        "continents": "北美洲",
        "countryShortCode": "USA",
        "countryName": "美國",
        "countryFullName": "United States of America",
        "currentConfirmedCount": 803916,
        "confirmedCount": 965785,
        "suspectedCount": 0,
        "curedCount": 106988,
        "deadCount": 54881,
        "incrVo": {
            "confirmedIncr": 0,
            "currentConfirmedIncr": 0,
            "curedIncr": 0,
            "deadIncr": 0
        }
    }
]

Detail

根據國家名稱獲取某個國家的疫情統計數據;

接口地址:/api/countries/<COUNTRY_NAME>/

請求方法:GET

示例連接:

http://111.231.75.86:8000/api/countries/美國/

http://111.231.75.86:8000/api/countries/巴西/

返回結果:

{
    "continents": "北美洲",
    "countryShortCode": "USA",
    "countryName": "美國",
    "countryFullName": "United States of America",
    "currentConfirmedCount": 803916,
    "confirmedCount": 965785,
    "suspectedCount": 0,
    "curedCount": 106988,
    "deadCount": 54881,
    "incrVo": {
        "confirmedIncr": 0,
        "currentConfirmedIncr": 0,
        "curedIncr": 0,
        "deadIncr": 0
    }
}

省/自治區/直轄市

Daily List(Chart Data)

經過短省份名獲取某個中國省份(自治區、直轄市)的疫情從 2020-01-19 到目前的疫情列表數據;

接口地址:/api/provinces/<PROVINCE_SHORT_NAME>/daily/

請求方法:GET

示例連接:

http://111.231.75.86:8000/api/provinces/四川/daily/

http://111.231.75.86:8000/api/provinces/臺灣/daily/

http://111.231.75.86:8000/api/provinces/香港/daily/

http://111.231.75.86:8000/api/provinces/澳門/daily/

返回結果:

[
    {
        "dateId": 20200119,
        "currentConfirmedCount": 188,
        "confirmedCount": 217,
        "suspectedCount": 0,
        "curedCount": 25,
        "deadCount": 4,
        "currentConfirmedIncr": 188,
        "confirmedIncr": 217,
        "suspectedCountIncr": 0,
        "curedIncr": 25,
        "deadIncr": 4
    },
    {
        "dateId": 20200120,
        "currentConfirmedCount": 188,
        "confirmedCount": 217,
        "suspectedCount": 0,
        "curedCount": 25,
        "deadCount": 4,
        "currentConfirmedIncr": 188,
        "confirmedIncr": 217,
        "suspectedCountIncr": 0,
        "curedIncr": 25,
        "deadIncr": 4
    },
    ...
]

List

獲取中國各中國省/自治區/直轄市的疫情統計數據;

接口地址:/api/provinces/

請求方法:GET

請求參數:

參數

描述

provinceNames

省份名(自治區、直轄市),如:黑龍江省、四川省、北京市;以逗號分割多個值;

provinceShortNames

短省份名(自治區、直轄市),如:黑龍江、四川、香港;以逗號分割多個值;

示例連接:

http://111.231.75.86:8000/api/provinces/?provinceShortNames=四川,香港

返回結果:

[
    {
        "provinceName": "黑龍江省",
        "provinceShortName": "黑龍江",
        "currentConfirmedCount": 367,
        "confirmedCount": 936,
        "suspectedCount": 384,
        "curedCount": 556,
        "deadCount": 13
    }
]

Detail

經過短省份名獲取某個中國省份(自治區、直轄市)的疫情統計數據;

接口地址:/api/provinces/<PROVINCE_SHORT_NAME>/

請求方法:GET

示例連接:

http://111.231.75.86:8000/api/provinces/四川/

http://111.231.75.86:8000/api/provinces/臺灣/

http://111.231.75.86:8000/api/provinces/香港/

http://111.231.75.86:8000/api/provinces/澳門/

返回結果:

{
    "provinceName": "黑龍江省",
    "provinceShortName": "黑龍江",
    "currentConfirmedCount": 367,
    "confirmedCount": 936,
    "suspectedCount": 384,
    "curedCount": 556,
    "deadCount": 13
}

城市或直轄市某區

List

獲取中國各個城市或直轄市某個區的疫情數據。

接口地址:/api/cities/

請求方法:GET

請求參數:

參數

描述

provinceShortNames

短省份名,如:黑龍江、四川;以逗號分割多個值;

cityNames

城市名,如:大慶、萬州區

示例連接:

http://111.231.75.86:8000/api/cities/?cityNames=大慶,萬州區

返回結果:

[
    {
        "provinceName": "黑龍江省",
        "cityName": "境外輸入",
        "currentConfirmedCount": 300,
        "confirmedCount": 386,
        "suspectedCount": 34,
        "curedCount": 86,
        "deadCount": 0
    }
]

Detail

接口地址:/api/cities/<CITY_NAME>/

請求方法:GET

示例連接:

http://111.231.75.86:8000/api/cities/大慶/

返回結果:

{
    "provinceName": "黑龍江省",
    "cityName": "哈爾濱",
    "currentConfirmedCount": 61,
    "confirmedCount": 260,
    "suspectedCount": 8,
    "curedCount": 195,
    "deadCount": 4
}
相關文章
相關標籤/搜索