LoginSignup
268
131

More than 3 years have passed since last update.

🇯🇵日本を対象とした🦠コロナウイルス情報 Web APIが無かったので2日間で公開した話

Last updated at Posted at 2020-04-02

今や社会課題と言っても過言では無いほど🦠コロナウイルス騒動は人々の注目を集めています。また、世界中のエンジニアがコロナウイルスに関するWebサイトやオープンソースプロダクトを開発しています。(GitHubでCOVID-19などで調べるとたくさん出てきます)その中で世界のコロナウイルス情報をWebAPIとして公開している人もいましたが、日本に特化したコロナウイルス情報WebAPIは無いみたいでした。(多分)
という背景もあり、今回は日本を対象としたコロナウイルス情報 Web APIを作ったら使う人もいるだろうなぐらいのノリで趣味として作成し、公開しました。

facebook_cover_photo_2.png
🚀 作成したリポジトリ (https://github.com/ryo-ma/covid19-japan-web-api)

使用技術

  • Python 3系
  • sanic (Python用 非同期Webアプリケーションフレームワーク, ASGI対応, ソニックのパチモノキャラをモチーフにしてる)
  • zeit now (Paas, GitHubと連携が可能でデプロイが簡単なPaaS) 現在は無料枠を利用
  • GitHub Action (GitHubのCI/CD)自動でデータ更新->デプロイするためのCI/CDとして利用

データソース

APIで提供するデータはGitHub上でcsvデータをオープンに公開してくれているリポジトリから収集してくることにしました。GitHub Actionを利用して2時間に1回データを更新してリポジトリにpushしています。

今後は分析結果などを公開してくれている他のリポジトリからの情報も利用したいと考えています。

データ更新 & デプロイ アーキテクチャ

zeit nowとGitHub Actionを利用することで2時間に1回データを更新してデプロイを自動で行います。

スクリーンショット 2020-04-01 16.08.21.png

開発期間

完璧さは求めずに、なるべく早く公開して少しずつ改善していこうというスタンスで行いました。

実装自体は大したことが無いのと、zeit nowとGitHub Actionの利用方法がとても簡単だったので、2日間という短い期間で基本機能を作成することができました。

1日目:
・静的に取得してきたデータを提供する県ごとのAPIを作成
・リポジトリ作成
・zeit nowとGitHub 自動デプロイ連携

2日目:
・GitHub Actionを利用しCI/CDとしてデータ自動更新に対応

以降:
・ API追加
・ README整備
など

作成したAPI

※ 追記:提供していただいているデータの変更により、以下のレスポンスは変わることもございます。

2020 4/20 追記:以下追加をしました
* Total History APIを追加
* Positives Statistics APIを追加

追加したAPIはリポジトリのREADMEにも記述されてます。
https://github.com/ryo-ma/covid19-japan-web-api

県ごとの感染数、死者数

Endpont: https://covid19-japan-web-api.now.sh/api/v1/prefectures

$ curl https://covid19-japan-web-api.now.sh/api/v1/prefectures

Response:

[
  {
    "id": 1,
    "name_ja": "北海道",
    "name_en": "Hokkaido",
    "lat": 43.46722222,
    "lng": 142.8277778,
    "cases": 176,
    "deaths": 7
  },
  {
    "id": 2,
    "name_ja": "青森",
    "name_en": "Aomori",
    "lat": 40.78027778,
    "lng": 140.83194440000003,
    "cases": 8,
    "deaths": 0
  },
...

国内の様々な集計データ

Endpont: https://covid19-japan-web-api.now.sh/api/v1/total

$ curl https://covid19-japan-web-api.now.sh/api/v1/total

Response:

{
  "date": 20200329,
  "pcr": 26401,
  "positive": 1647,
  "symptom": 1352,
  "symptomless": 162,
  "symtomConfirming": 133,
  "hospitalize": 1187,
  "mild": 659,
  "severe": 59,
  "confirming": 323,
  "waiting": 13,
  "discharge": 408,
  "death": 52
}

国内、現在から過去の集計データ

Endpoint: https://covid19-japan-web-api.now.sh/api/v1/total?history=true

$ curl https://covid19-japan-web-api.now.sh/api/v1/total?history=true
[
  {
    "date": 20200206,
    "pcr": 132,
    "positive": 16,
    "symptom": 16,
    "symptomless": 0,
    "symptomConfirming": 0,
    "hospitalize": 9,
    "mild": 0,
    "severe": 0,
    "confirming": 3,
    "waiting": 0,
    "discharge": 4,
    "death": 0
  },
  {
    "date": 20200207,
    "pcr": 151,
    "positive": 16,
    "symptom": 16,
    "symptomless": 0,
    "symptomConfirming": 0,
    "hospitalize": 12,
    "mild": 0,
    "severe": 0,
    "confirming": 0,
    "waiting": 0,
    "discharge": 4,
    "death": 0
  },
...

陽性者一覧

※2020/04/16 追記:全件取得が無くなりました。prefectureが必須パラメータとなります。

Endpont: https://covid19-japan-web-api.now.sh/api/v1/positives?perefecture=東京都

$ curl https://covid19-japan-web-api.now.sh/api/v1/positives?prefecture=東京都

Response:

[
  {
    "code": "",
    "announcement_date": "2020-01-24",
    "src": "https://www.metro.tokyo.lg.jp/tosei/hodohappyo/press/2020/01/24/20.html",
    "prefecture": "東京都",
    "residence_prefecture": "国外(武漢市)",
    "age": "40代",
    "gender": "男性",
    "attribute": "",
    "prefecture_number": "東京都1",
    "travel_or_contact": "渡航歴",
    "detail": "中国(武漢)",
    "id": "ID130001",
    "diagnosis_date": "",
    "onset": "2020/01/14",
    "symptom": "1",
    "death_or_discharge_date": "",
    "comment": "",
    "outcome": "1",
    "outcome_src": "https://i.imgur.com/P185t7C.jpg"
  },
  {
    "code": "",
    "announcement_date": "2020-01-25",
    "src": "https://www.metro.tokyo.lg.jp/tosei/hodohappyo/press/2020/01/27/24.html",
    "prefecture": "東京都",
    "residence_prefecture": "国外(武漢市)",
    "age": "30代",
    "gender": "女性",
    "attribute": "",
    "prefecture_number": "東京都2",
    "travel_or_contact": "渡航歴",
    "detail": "中国(武漢)",
    "id": "ID130002",
    "diagnosis_date": "",
    "onset": "2020/01/21",
    "symptom": "1",
    "death_or_discharge_date": "",
    "comment": "",
    "outcome": "1",
    "outcome_src": "https://i.imgur.com/P185t7C.jpg"
  },
...

感染者の集計データ

陽性者一覧のAPIから集計したもので、公開されていないデータは含まれていません。
性別、年齢別に集計を行なっています。

Endpoint: https://covid19-japan-web-api.now.sh/api/v1/statistics

[
  {
    "name_ja": "北海道",
    "name_en": "Hokkaido",
    "total_count": 239,
    "male": {
      "count": 137,
      "generations_count": {
        "00s": 6,
        "10s": 1,
        "20s": 5,
        "30s": 8,
        "40s": 19,
        "50s": 35,
        "60s": 27,
        "70s": 19,
        "80s": 14,
        "90s": 2,
        "100s": 0,
        "unknown": 1
      }
    },
    "female": {
      "count": 100,
      "generations_count": {
        "00s": 1,
        "10s": 1,
        "20s": 14,
        "30s": 10,
        "40s": 12,
        "50s": 17,
        "60s": 15,
        "70s": 16,
        "80s": 8,
        "90s": 4,
        "100s": 0,
        "unknown": 2
      }
    },
    "unkown_gender": {
      "count": 2,
      "generations_count": {
        "00s": 0,
        "10s": 0,
        "20s": 0,
        "30s": 0,
        "40s": 0,
        "50s": 0,
        "60s": 0,
        "70s": 0,
        "80s": 0,
        "90s": 0,
        "100s": 0,
        "unknown": 2
      }
    }
  },
...

まとめ

今回は短期間で日本のコロナウイルスWebAPIを公開しました。
誰かがこのAPIを利用して、コロナウイルス情報の拡散の手助けに少しでもなればいいなと考えております。

🏁APIの仕様に対しての要望や質問、プルリクエストなどお待ちしております。
リポジトリhttps://github.com/ryo-ma/covid19-japan-web-api

268
131
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
268
131