GitHub Actions で手動トリガーのワークフローを作る

qiita.com

github.com

personal access token

Settings / Developer settings / Personal access tokens

public_repo をチェック

f:id:imabari_ehime:20200504205057p:plain

workflows

on:
  repository_dispatch:
    types: [on-demand-test]
  schedule:
    - cron:  '0 12 * * *'

command

curl --request POST \
  --url https://api.github.com/repos/imabari/kumamoto-covid19/dispatches \
  --header "Authorization: token $GITHUB_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{"event_type": "on-demand-test"}'

オンライン診療対応医療機関のPDFをCSVに変換

www.mhlw.go.jp

import requests
from bs4 import BeautifulSoup

from urllib.parse import urljoin

import camelot
import pandas as pd


url = "https://www.mhlw.go.jp/stf/seisakunitsuite/bunya/kenkou_iryou/iryou/rinsyo/index_00014.html"

headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko"}

r = requests.get(url, headers=headers)

r.raise_for_status()

soup = BeautifulSoup(r.content, "html5lib")

for i in soup.select("ul.m-listLink--hCol2 > li > a"):

    link = urljoin(url, i.get("href"))

    print(i.get_text(), link)

    tables = camelot.read_pdf(link, pages="all")

    df = pd.concat([table.df for table in tables])

    df.to_csv(f"{i.get_text()}.csv", index=None, header=None)

feed43でオンライン診療対応医療機関リストの情報更新をRSS

オンライン診療対応医療機関リストの情報更新をRSSなし、Googleスプレッドシートだけで確認できるようにしてみた

dev.classmethod.jp

Global Search Pattern (optional)を使えばいい

f:id:imabari_ehime:20200501180301p:plain

<ul class="m-listLink--hCol2">{%}</ul>

<li><a href="{%}">{%}</a></li>

北海道・東北・関東地方

feed43.com

中部・近畿地方

feed43.com

中国・四国・九州地方

feed43.com

新型コロナウイルスまとめサイトdata.json(集計方法)

サンプル富山県

github.com

欠損日付を0で補間

# IndexはDatetimeIndex
df.asfreq("D", fill_value=0)

pandas.pydata.org

import pandas as pd
import matplotlib.pyplot as plt

import japanize_matplotlib

# 設定

COUNTS_FILE = "toyama_counts.csv"
PATIENTS_FILE = "toyama_patients.csv"

# ダウンロード

!wget "https://docs.google.com/spreadsheets/d/e/2PACX-1vSJuQThafLPC7OPqUC9TbLV1DmSU0x2Co8VZi2Q2ZZCKLJCTayDl6IoXKyK676mzBgpkoKMgpNK1VML/pub?gid=0&single=true&output=csv" -O $PATIENTS_FILE
!wget "https://docs.google.com/spreadsheets/d/e/2PACX-1vSJuQThafLPC7OPqUC9TbLV1DmSU0x2Co8VZi2Q2ZZCKLJCTayDl6IoXKyK676mzBgpkoKMgpNK1VML/pub?gid=574469870&single=true&output=csv" -O $COUNTS_FILE

# 内容確認

## 日別データ


df_counts = pd.read_csv(COUNTS_FILE, index_col="年月日", parse_dates=True, dtype={"備考": "object"})

df_counts.head(10)

## 患者データ

df_kanja = pd.read_csv(PATIENTS_FILE, index_col="No", dtype={"発症日": "object", "年代": "object", "備考": "object"})

df_kanja.head(10)

# 一般

## 検査実施状況


df_counts.tail(1)

## 陽性患者数

#日別
df_counts["陽性人数"].plot.bar()

# 累計
df_counts["陽性人数"].cumsum().plot.bar()

## 検査実施人数

# 日別
df_counts["検査実施人数"].plot.bar()

# 累計
df_counts["検査実施人数"].cumsum().plot.bar()

## 相談件数

# 日別
df_counts["一般相談件数"].plot.bar()

# 累計
df_counts["一般相談件数"].cumsum().plot.bar()

# その他

## 現在患者数

df_counts["現在患者数"] = df_counts["陽性人数"] - df_counts["退院者数"] - df_counts["死亡者数"]

# 日別
df_counts["現在患者数"].plot.bar()

# 累計
df_counts["現在患者数"].cumsum().plot.bar()

## 治療修了者数

# 日別
df_counts["退院者数"].plot.bar()

# 累計
df_counts["退院者数"].cumsum().plot.bar()

## 年代別

age_lists = ["10歳未満", "10代", "20代", "30代", "40代", "50代", "60代", "70代", "80代", "90代以上"]
df_kanja["年代"].value_counts().reindex(age_lists).plot.bar()

## 居住地別

df_kanja["居住地"].value_counts().plot.bar()

## 陽性率

df_positive = df_counts.loc[:, ["検査実施人数", "陽性人数"]].copy()

# 3日間平均
df_positive_3d = df_positive.rolling(window=3).mean()
df_positive_3d["陽性率"] = df_positive_3d["陽性人数"] / df_positive_3d["検査実施人数"] * 100
df_positive_3d["陽性率"].plot(ylim=(0, 50))

# 7日間平均
df_positive_2w = df_positive.rolling(window=7).mean()
df_positive_2w["陽性率"] = df_positive_2w["陽性人数"] / df_positive_2w["検査実施人数"] * 100
df_positive_2w["陽性率"].plot(ylim=(0, 50))

# 補正なし
df_positive["陽性率"] = df_positive["陽性人数"] / df_positive["検査実施人数"] * 100
df_positive["陽性率"].plot(ylim=(0, 50))

富山県のコロナ情報をオープンデータに変換

ChromeFirefox・最新のEdgeで実行

こちらにアクセス

github.com

1.ボタンをクリック

f:id:imabari_ehime:20200426134633p:plain

2.メニューの「ランタイム」-「すべてのセルを実行」の順にクリック

f:id:imabari_ehime:20200426134644p:plain

3.このまま実行をクリック

f:id:imabari_ehime:20200426134654p:plain

4.ダウンロード画面が表示されるのでダウンロード