Web で閲覧できる次の表を作成します。
データのソースは埼玉県です。
CSV を JSON へ変換
iconv -f sjis -t UTF-8 jokyo20200330.csv > saitama.csv
./saitama_corona.py saitama.csv data_saitama.json
saitama_corona.py
# ! /usr/bin/python
# -*- coding: utf-8 -*-
#
# saitama_corona.py
#
# Apr/01/2020
#
import sys
import string
import json
import csv
#
# ------------------------------------------------------------------
def parse_proc(dict_aa,row):
ix = int(row[0])
key = "s%03d" % ix
unit_aa = {}
unit_aa['date'] = row[1]
unit_aa['age'] = row[2]
unit_aa['sex'] = row[3]
unit_aa['place'] = row[4]
unit_aa['status'] = row[5]
dict_aa[key] = unit_aa
#
return dict_aa
# ------------------------------------------------------------------
sys.stderr.write ("*** 開始 ***\n")
file_csv = sys.argv[1]
file_json = sys.argv[2]
sys.stderr.write(file_csv + "\n")
sys.stderr.write(file_json + "\n")
#
fp = open(file_csv, 'r')
reader = csv.reader(fp)
dict_aa = {}
for row in reader:
if row[0] != "No.":
dict_aa = parse_proc(dict_aa,row)
#
fp.close()
#
dict_bb = {}
for key in sorted(dict_aa.keys(), reverse=True):
dict_bb[key] = dict_aa[key]
#
json_str = json.dumps(dict_bb)
#
fp_out = open(file_json,mode='w',encoding='utf-8')
fp_out.write(json_str)
fp_out.close()
#
sys.stderr.write ("*** 終了 ***\n")
# ------------------------------------------------------------------
ホームページ
saitama_patient.html
<!DOCTYPE html>
<html lang="ja">
<head>
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8" />
<script src="/js/jquery-3.4.1.min.js"></script>
<script src="saitama_patient.js"></script>
<link rel="stylesheet" href="saitama_patient.css">
<title>埼玉県の新型コロナウイルス感染症患者の発生状況</title>
</head>
<body>
<blockquote>
<h2>埼玉県の新型コロナウイルス感染症患者の発生状況</h2><p />
<blockquote>
(3月30日 17:30時点)<p />
</blockquote>
</blockquote>
<blockquote>
<div class="contents"></div>
</blockquote>
</blockquote>
<hr />
データソース
<blockquote>
<a href="https://opendata.pref.saitama.lg.jp/data/dataset/c3a8db28-b943-4fcc-82ec-b7febd460bec/resource/8af433a5-9efd-428f-8713-b04bd2451d1a/download/jokyo20200330.csv">埼玉県内の新型コロナウイルス感染症の発生状況(2020/03/30 17:30)</a><p />
</blockquote>
<a href="../">Return</a><p />
Apr/01/2020 AM 07:00<p />
</body>
</html>
saitama_patient.css
/* -------------------------------------------------------------- */
/*
saitama_patient.css
Mar/31/2020
*/
/* -------------------------------------------------------------- */
table.main,td,th {
table-layout:fixed;
border:1.5px #7e7e7e solid;
border-collapse: collapse;
height: 16px;
}
th {
background: #c6c6c6;
}
table.tag {
border:0.5px green solid;
}
tr.cyan {
background-color: #c7d7c7;
}
.red {color:#ff0000;}
/* -------------------------------------------------------------- */
saitama_patient.js
// -----------------------------------------------------------------------
// saitama_patient.js
//
// Mar/31/2020
//
// -----------------------------------------------------------------------
jQuery (function ()
{
jQuery("#outarea_aa").text ("*** saitama_patient *** start ***")
const file_in = "./data_saitama.json"
jQuery.getJSON (file_in,function (data_aa)
{
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 += "<th>現状</th>"
str_out += "</tr>"
for (var key in data_aa)
{
const unit_aa = data_aa[key]
str_out += "<tr>"
str_out += "<td>" + key + "</td>"
str_out += "<td>" + unit_aa.date + "</td>"
str_out += "<td>" + unit_aa.age + "</td>"
str_out += "<td>" + unit_aa.sex + "</td>"
str_out += "<td>" + unit_aa.place + "</td>"
str_out += "<td>" + unit_aa.status + "</td>"
str_out += "</tr>"
}
str_out += "</table>"
jQuery(".contents").html (str_out)
})
jQuery("#outarea_hh").text ("*** saitama_patient *** end ***")
})
// -----------------------------------------------------------------------
