Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #212 from covid19-miyazaki/staging
Browse files Browse the repository at this point in the history
Release 2020-05-10 01:14:59 +0900
  • Loading branch information
korosuke613 authored May 10, 2020
2 parents 93124d7 + 30e3874 commit 6aa5182
Show file tree
Hide file tree
Showing 14 changed files with 360 additions and 419 deletions.
29 changes: 26 additions & 3 deletions .github/workflows/news_scraping.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ jobs:
- /dev/shm:/dev/shm
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/setup-ruby@v1
with:
ruby-version: '2.5'
- name: execute
- name: Scraping News
env:
URL: "https://www.pref.miyazaki.lg.jp/kenko/hoken/kansensho/covid19/hassei.html"
SELENIUM_HOST: localhost
Expand All @@ -30,6 +28,7 @@ jobs:
bundle install
ruby scraping.rb
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v2
with:
commit-message: 'Update news.json'
Expand All @@ -39,3 +38,27 @@ jobs:
branch-suffix: timestamp
title: '最新のお知らせ更新'
body: '公式サイトのお知らせが更新されました。差分を確認してマージしてください。'
token: ${{ secrets.BOT_TOKEN }}
# ここから下はお知らせに差分があった場合のみ実行する
- uses: actions/checkout@v2
if: steps.cpr.outputs.pr_number != 0
- name: Scraping Data
env:
URL: "https://www.pref.miyazaki.lg.jp/kenko/hoken/kansensho/covid19/hassei.html"
SELENIUM_HOST: localhost
TZ: Asia/Tokyo
run: |
ruby scraping_data.rb
if: steps.cpr.outputs.pr_number != 0
- name: Create Pull Request
uses: peter-evans/create-pull-request@v2
with:
commit-message: 'Update data.json'
branch: data
base: master
# labels: auto_merge
branch-suffix: timestamp
title: '陽性患者数更新'
body: '公式サイトの情報が更新されました。差分を確認してマージしてください。'
token: ${{ secrets.BOT_TOKEN }}
if: steps.cpr.outputs.pr_number != 0
4 changes: 2 additions & 2 deletions .github/workflows/scraping.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ env:
TZ: 'Asia/Tokyo'
on:
schedule:
- cron: '0 */12 * * *'
- cron: '0 */6 * * *'
jobs:
scraping:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -49,9 +49,9 @@ jobs:
- name: Create Pull Request
uses: peter-evans/create-pull-request@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: コロナ情報の更新
commit-message: コロナ情報を更新しました.
branch: auto_update_covid19
labels: auto_merge
base: master
token: ${{ secrets.BOT_TOKEN }}
2 changes: 1 addition & 1 deletion assets/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"日南市": "Nichinan",
"串間市": "Kushima",
"高千穂町": "Takachiho",
"{age}代": " {age}s",
"{ageHead}歳〜{ageTail}歳": " {ageHead}s",
"10歳未満": "Under 10 years old",
"男性": "Male",
"女性": "Female",
Expand Down
460 changes: 218 additions & 242 deletions assets/locales/ja-Hira.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"埼玉県": "埼玉県",
"湖南省長沙市": "湖南省長沙市",
"湖北省武漢市": "湖北省武漢市",
"{age}代": "{age}代",
"{ageHead}歳〜{ageTail}歳": "{ageHead}代",
"10歳未満": "10歳未満",
"男性": "男性",
"女性": "女性",
Expand Down
15 changes: 15 additions & 0 deletions components/DataTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@
:mobile-breakpoint="0"
class="cardTable"
>
<template v-slot:header.公表日="{ header }">
<t-i18n>{{ header.text }}</t-i18n>
</template>
<template v-slot:header.居住地="{ header }">
<t-i18n>{{ header.text }}</t-i18n>
</template>
<template v-slot:header.年代="{ header }">
<t-i18n>{{ header.text }}</t-i18n>
</template>
<template v-slot:header.性別="{ header }">
<t-i18n>{{ header.text }}</t-i18n>
</template>
<template v-slot:header.退院="{ header }">
<t-i18n>{{ header.text }}</t-i18n>
</template>
<template v-slot:body="{ items }">
<tbody>
<tr v-for="item in items" :key="item.text">
Expand Down
5 changes: 3 additions & 2 deletions components/cards/ConfirmedCasesAttributesCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ export default {
} else if (row['年代'] === '不明') {
row['年代'] = this.$t('不明')
} else {
const age = row['年代'].substring(0, 2)
row['年代'] = this.$t('{age}代', { age })
const ageHead = row['年代'].substring(0, 2)
const ageTail = String(Number(ageHead) + 9)
row['年代'] = this.$t('{ageHead}歳〜{ageTail}歳', { ageHead, ageTail })
}
}
Expand Down
18 changes: 9 additions & 9 deletions data/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@
"居住地": "宮崎市",
"年代": "40代",
"性別": "男性",
"退院": "入院中",
"date": "2020-04-06"
"退院": "退院",
"date": "2020-04-29"
},
{
"リリース日": "2020-04-07T08:00:00.000Z",
Expand All @@ -104,8 +104,8 @@
"居住地": "日南市",
"年代": "30代",
"性別": "女性",
"退院": "入院中",
"date": "2020-04-08"
"退院": "退院",
"date": "2020-04-29"
},
{
"リリース日": "2020-04-08T08:00:00.000Z",
Expand Down Expand Up @@ -136,8 +136,8 @@
"居住地": "宮崎市",
"年代": "50代",
"性別": "女性",
"退院": "入院中",
"date": "2020-04-11"
"退院": "退院",
"date": "2020-05-09"
}
]
},
Expand All @@ -151,11 +151,11 @@
"children": [
{
"attr": "入院中",
"value": 8,
"value": 5,
"children": [
{
"attr": "軽症・中等症",
"value": 8
"value": 5
},
{
"attr": "重症",
Expand All @@ -165,7 +165,7 @@
},
{
"attr": "退院",
"value": 9
"value": 12
},
{
"attr": "死亡",
Expand Down
2 changes: 1 addition & 1 deletion data/news.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@
"text": "新型コロナウイルス感染症患者(2例目、3例目)の発生について(続報)"
}
]
}
}
7 changes: 4 additions & 3 deletions scraping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
puts news

# JSON出力
File.open("data/news.json", 'w') do |file|
str = JSON.dump(news, file)
end
news_json = JSON.pretty_generate(news, {:indent => " "})
File.open("data/news.json", mode = "w") { |f|
f.write(news_json)
}

exit

2 changes: 1 addition & 1 deletion scrapingSource/Scraping.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def set_parse_table_data_to_json(self):
"""
self.json["lastUpdate"] = self.get_time()
self.json["patients"]["date"] = self.get_time()
self.json["main_summary"]["value"] = int(self.covid_data[0])
self.json["main_summary"]["value"] = int(self.covid_data[0].replace(',', ''))
self.json["main_summary"]["children"][0]["value"] = int(self.covid_data[1])
json.dump(self.json, open(self.json_path, 'w'), indent=4, ensure_ascii=False)

Expand Down
67 changes: 67 additions & 0 deletions scraping_data.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
require 'selenium-webdriver'
require 'date'

today = Date.today.strftime("%Y/%m/%d")
driver = Selenium::WebDriver.for :remote, desired_capabilities: :chrome, url: "http://#{ENV['SELENIUM_HOST']}:4444/wd/hub"

# 最新ニュースのURL取得
driver.navigate.to(ENV['URL'])
list_table = driver.find_element(:class => "list_table")
urls = list_table.find_elements(:tag_name => "a")
url = urls[0].attribute("href")

# 最新ニュースをスクレイピング
driver.navigate.to(url)
uls = driver.find_elements(:class => "noicon")
count = uls.length - 1
datas = []
for i in 0..count do
data = { "リリース日" => today, "退院" => "入院中", "date" => today }
ul = uls[i]

address = ul.text.match(/居住地(.+)/)
if address
data["居住地"] = address[1]
else
next
end

age = ul.text.match(/年齢(.+)/)
if age
data["年代"] = age[1]
else
next
end

gender = ul.text.match(/性別(.+)/)
if gender
data["性別"] = gender[1]
else
next
end

datas.push(data)
end

data_count = datas.length

data_hash = {}
File.open("data/data.json") do |file|
data_hash = JSON.load(file)
end

# data.json を更新
data_hash["lastUpdate"] = today
data_hash["patients"]["date"] = today
data_hash["patients"]["data"].concat(datas)
data_hash["main_summary"]["children"][0]["value"] = data_hash["main_summary"]["children"][0]["value"] + data_count
data_hash["main_summary"]["children"][0]["children"][0]["value"] = data_hash["main_summary"]["children"][0]["children"][0]["value"] + data_count
data_hash["main_summary"]["children"][0]["children"][0]["children"][0]["value"] = data_hash["main_summary"]["children"][0]["children"][0]["children"][0]["value"] + data_count
data_hash["patients_summary"]["data"].push({ "日付" => today, "小計" => data_count })

data_json = JSON.pretty_generate(data_hash, {:indent => " "})
File.open("data/data.json", mode = "w") { |f|
f.write(data_json)
}

exit
2 changes: 1 addition & 1 deletion utils/ruby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const createRubyObject = (text: string) => {
let lastText: string
let pos = 0
const texts: RubyText[] = []
const regp = /([\p{sc=Han}|\s|・]+?)(([\p{sc=Hiragana}|\s|・]+?))/gu
const regp = /([\p{sc=Han}|・|A-z]+?)(([\p{sc=Hiragana}|\p{sc=Katakana}|ー|・]+?))/gu

// ふりがなを含んだ文字列をパースしてオブジェクトを生成
while ((match = XRegExp.exec(text, regp, pos))) {
Expand Down
Loading

0 comments on commit 6aa5182

Please sign in to comment.