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

Commit

Permalink
Merge branch 'development' into ticket-184
Browse files Browse the repository at this point in the history
  • Loading branch information
korosuke613 authored May 4, 2020
2 parents efd9fcd + 957adc3 commit e98fcbf
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 17 deletions.
27 changes: 24 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,25 @@ jobs:
branch-suffix: timestamp
title: '最新のお知らせ更新'
body: '公式サイトのお知らせが更新されました。差分を確認してマージしてください。'
# ここから下はお知らせに差分があった場合のみ実行する
- 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: '公式サイトの情報が更新されました。差分を確認してマージしてください。'
if: steps.cpr.outputs.pr_number != 0
20 changes: 10 additions & 10 deletions data/data.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"lastUpdate": "2020/04/26",
"lastUpdate": "2020/04/29",
"patients": {
"date": "2020/04/26",
"date": "2020/04/29",
"data": [
{
"リリース日": "2020-03-04T08:00:00.000Z",
Expand Down 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 @@ -143,19 +143,19 @@
},
"main_summary": {
"attr": "検査実施人数",
"value": 925,
"value": 993,
"children": [
{
"attr": "陽性患者数",
"value": 17,
"children": [
{
"attr": "入院中",
"value": 8,
"value": 6,
"children": [
{
"attr": "軽症・中等症",
"value": 8
"value": 6
},
{
"attr": "重症",
Expand All @@ -165,7 +165,7 @@
},
{
"attr": "退院",
"value": 9
"value": 11
},
{
"attr": "死亡",
Expand Down
55 changes: 54 additions & 1 deletion data/news.json
Original file line number Diff line number Diff line change
@@ -1 +1,54 @@
{"newsItems":[{"date":"2020年4月11日","url":"https://www.pref.miyazaki.lg.jp/kohosenryaku/kenko/hoken/covid19_20200411.html","text":"新型コロナウイルス感染症患者(第17例目)の発生について(第一報)"},{"date":"2020年4月8日","url":"https://www.pref.miyazaki.lg.jp/kohosenryaku/kenko/hoken/covid19_20200408.html","text":"新型コロナウイルス感染症患者(第13~16例目)の発生について(第一報)"},{"date":"2020年4月7日","url":"https://www.pref.miyazaki.lg.jp/kohosenryaku/kenko/hoken/20200407.html","text":"新型コロナウイルス感染症患者(第12例目)の発生について(第一報)"},{"date":"2020年4月7日","url":"https://www.pref.miyazaki.lg.jp/kohosenryaku/kenko/hoken/covid19_20200304.html","text":"新型コロナウイルス感染症患者(第1例目)の発生について(続報)"},{"date":"2020年4月6日","url":"https://www.pref.miyazaki.lg.jp/kohosenryaku/kenko/hoken/covid19_20200406.html","text":"新型コロナウイルス感染症患者(第11例目)の発生について(第一報)"},{"date":"2020年4月5日","url":"https://www.pref.miyazaki.lg.jp/kohosenryaku/kenko/hoken/covid19_20200405.html","text":"新型コロナウイルス感染症患者(第9、10例目)の発生について(第一報)"},{"date":"2020年4月4日","url":"https://www.pref.miyazaki.lg.jp/kohosenryaku/kenko/hoken/covid19_20200404.html","text":"新型コロナウイルス感染症患者(8例目)の発生について(第一報)"},{"date":"2020年4月4日","url":"https://www.pref.miyazaki.lg.jp/kohosenryaku/kenko/hoken/covid19_20200403.html","text":"新型コロナウイルス感染症患者(4例目)の発生について(続報)"},{"date":"2020年4月3日","url":"https://www.pref.miyazaki.lg.jp/kohosenryaku/kenko/hoken/covid19_20200403-2.html","text":"新型コロナウイルス感染症患者(5~7例目)の発生について(第一報)"},{"date":"2020年4月3日","url":"https://www.pref.miyazaki.lg.jp/kohosenryaku/kenko/hoken/covid19_20200317.html","text":"新型コロナウイルス感染症患者(2例目、3例目)の発生について(続報)"}]}
{
"newsItems": [
{
"date": "2020年4月11日",
"url": "https://www.pref.miyazaki.lg.jp/kohosenryaku/kenko/hoken/covid19_20200411.html",
"text": "新型コロナウイルス感染症患者(第17例目)の発生について(第一報)"
},
{
"date": "2020年4月8日",
"url": "https://www.pref.miyazaki.lg.jp/kohosenryaku/kenko/hoken/covid19_20200408.html",
"text": "新型コロナウイルス感染症患者(第13~16例目)の発生について(第一報)"
},
{
"date": "2020年4月7日",
"url": "https://www.pref.miyazaki.lg.jp/kohosenryaku/kenko/hoken/20200407.html",
"text": "新型コロナウイルス感染症患者(第12例目)の発生について(第一報)"
},
{
"date": "2020年4月7日",
"url": "https://www.pref.miyazaki.lg.jp/kohosenryaku/kenko/hoken/covid19_20200304.html",
"text": "新型コロナウイルス感染症患者(第1例目)の発生について(続報)"
},
{
"date": "2020年4月6日",
"url": "https://www.pref.miyazaki.lg.jp/kohosenryaku/kenko/hoken/covid19_20200406.html",
"text": "新型コロナウイルス感染症患者(第11例目)の発生について(第一報)"
},
{
"date": "2020年4月5日",
"url": "https://www.pref.miyazaki.lg.jp/kohosenryaku/kenko/hoken/covid19_20200405.html",
"text": "新型コロナウイルス感染症患者(第9、10例目)の発生について(第一報)"
},
{
"date": "2020年4月4日",
"url": "https://www.pref.miyazaki.lg.jp/kohosenryaku/kenko/hoken/covid19_20200404.html",
"text": "新型コロナウイルス感染症患者(8例目)の発生について(第一報)"
},
{
"date": "2020年4月4日",
"url": "https://www.pref.miyazaki.lg.jp/kohosenryaku/kenko/hoken/covid19_20200403.html",
"text": "新型コロナウイルス感染症患者(4例目)の発生について(続報)"
},
{
"date": "2020年4月3日",
"url": "https://www.pref.miyazaki.lg.jp/kohosenryaku/kenko/hoken/covid19_20200403-2.html",
"text": "新型コロナウイルス感染症患者(5~7例目)の発生について(第一報)"
},
{
"date": "2020年4月3日",
"url": "https://www.pref.miyazaki.lg.jp/kohosenryaku/kenko/hoken/covid19_20200317.html",
"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

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

0 comments on commit e98fcbf

Please sign in to comment.