データの取得
wget https://www.kantei.go.jp/jp/content/IRYO-vaccination_data.xlsx
wget https://www.kantei.go.jp/jp/content/KOREI-vaccination_data.xlsx
エクセルを JSON に変換
./xlsx_to_json_daily.py IRYO-vaccination_data.xlsx IRYO-vaccination_data.json
./xlsx_to_json_daily.py KOREI-vaccination_data.xlsx KOREI-vaccination_data.json
xlsx_to_json_daily.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# xlsx_to_json_daily.py
#
# May/21/2021
#
# -------------------------------------------------------------------
import sys
import json
from openpyxl import load_workbook
# -------------------------------------------------------------------
def file_write_proc(file_name,str_out):
#
fp_out = open(file_name,mode='w',encoding='utf-8')
fp_out.write(str_out)
fp_out.close()
#
# -------------------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")
file_xlsx = sys.argv[1]
file_json = sys.argv[2]
sys.stderr.write(file_xlsx + "\n")
#
wb = load_workbook(filename = file_xlsx)
ws = wb.active
sys.stderr.write("%d\n" % ws.max_column)
sys.stderr.write("%d\n" % ws.max_row)
#
array_out = []
icount = 0
for row in ws.rows:
if row[2].value != None:
unit_aa = {}
unit_aa["date"] = str(row[0].value)
unit_aa["number"] = row[2].value
unit_aa["first"] = row[3].value
unit_aa["second"] = row[4].value
array_out.append(unit_aa)
#
out_str = json.dumps(array_out)
file_write_proc(file_json,out_str)
# print(out_str)
sys.stderr.write("*** 終了 ***\n")
# -------------------------------------------------------------------
Web ページ
index.html
<!DOCTYPE html>
<html lang="ja">
<head>
<meta http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="vaccine_daily.css">
<title>日本のワクチン接種回数</title>
</head>
<body>
<blockquote>
<h2>日本のワクチン接種回数</h2><p />
</blockquote>
<blockquote>
<div class="contents"></div>
</blockquote>
</blockquote>
<hr />
データソース<br />
<blockquote>
<a href="https://www.kantei.go.jp/jp/headline/kansensho/vaccine.html">
新型コロナワクチンについて</a><br />
</blockquote>
<a href="../">Return</a><p />
May/21/2020 AM 08:00<p />
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="vaccine_daily.js"></script>
</body>
</html>
vaccine_daily.js
// -----------------------------------------------------------------------
// vaccine_daily.js
//
// May/18/2021
//
// -----------------------------------------------------------------------
jQuery (function ()
{
jQuery("#outarea_aa").text ("*** vaccine_daily *** start ***")
const file_korei = "./KOREI-vaccination_data.json"
const file_iryo = "./IRYO-vaccination_data.json"
jQuery.getJSON (file_korei,function (data_korei_raw)
{
const data_korei = filter_proc(data_korei_raw)
jQuery.getJSON (file_iryo,function (data_iryo_raw)
{
const data_iryo = filter_proc(data_iryo_raw)
const data_merged = merge_proc(data_korei,data_iryo)
create_table_proc(data_merged)
})
})
jQuery("#outarea_hh").text ("*** vaccine_daily *** end ***")
})
// -----------------------------------------------------------------------
function merge_proc(data_korei,data_iryo)
{
const dict_korei = array_to_dict_proc(data_korei)
const dict_iryo = array_to_dict_proc(data_iryo)
for (var key in dict_korei)
{
dict_korei[key]["iryo_number"] = 0
dict_korei[key]["iryo_first"] = 0
dict_korei[key]["iryo_second"] = 0
if (dict_iryo[key])
{
dict_korei[key]["iryo_first"] = dict_iryo[key]["first"]
dict_korei[key]["iryo_second"] = dict_iryo[key]["second"]
dict_korei[key]["iryo_number"] = dict_iryo[key]["first"] + dict_iryo[key]["second"]
}
dict_korei[key]["sum"] = dict_korei[key]["number"] + dict_korei[key]["iryo_number"]
}
return dict_korei
}
// -----------------------------------------------------------------------
function array_to_dict_proc(array_in)
{
var dict_out = {}
for (var it in array_in)
{
const unit_aa = array_in[it]
const key = unit_aa["date"]
dict_out[key] = unit_aa
}
return dict_out
}
// -----------------------------------------------------------------------
function create_table_proc(data_korei)
{
var str_out = ""
str_out += "<table>"
str_out += "<tr>"
str_out += "<th>No</th>"
str_out += "<th>接種日</th>"
str_out += "<th>総接種回数</th>"
str_out += "<th>内 高齢者等</th>"
str_out += "<th>内 医療従事者等</th>"
str_out += "</tr>"
var count = 1
for (var key in data_korei)
{
const unit_aa = data_korei[key]
str_out += "<tr>"
str_out += "<td>" + count + "</td>"
// str_out += "<td>" + unit_aa["date"] + "</td>"
str_out += "<td>" + key + "</td>"
str_out += "<td>" + unit_aa["sum"] + "</td>"
str_out += "<td>" + unit_aa["number"] + "</td>"
// str_out += "<td>" + unit_aa["first"] + "</td>"
// str_out += "<td>" + unit_aa["second"] + "</td>"
str_out += "<td>" + unit_aa["iryo_number"] + "</td>"
// str_out += "<td>" + unit_aa["iryo_first"] + "</td>"
// str_out += "<td>" + unit_aa["iryo_second"] + "</td>"
str_out += "</tr>"
count += 1
}
str_out += "</table>"
jQuery(".contents").html (str_out)
}
// -----------------------------------------------------------------------
function filter_proc(data_in)
{
var data_out = []
count = 0
for (var key in data_in)
{
// if ((4 <= key) && (key <= 50))
if (2 <= key)
{
data_out.push(data_in[key])
}
}
return data_out
}
// -----------------------------------------------------------------------
vaccine_daily.css
/* -------------------------------------------------------------- */
/*
vaccine_daily.css
May/22/2021
*/
/* -------------------------------------------------------------- */
table.main,td,th {
table-layout:fixed;
border:1.5px #7e7e7e solid;
border-collapse: collapse;
height: 16px;
}
th {
background: #c6c6c6;
}
/* -------------------------------------------------------------- */