0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

群馬県の新型コロナウイルス感染症患者の発生状況の表を作成

Last updated at Posted at 2020-03-31

Web で閲覧できる次の表を作成します。

群馬県の新型コロナウイルス感染症患者の発生状況
gunma_patient.png

データのソースは群馬県です。

群馬県内における新型コロナウイルス感染症発生状況(令和2年3月29日現在)

PDF を JSON へ変換

pdftotext -layout 100149743.pdf
#
./gunma_corona.py 100149743.txt data_gunma.json
gunma_corona.py
#! /usr/bin/python
# -*- coding: utf-8 -*-
#
#	gunma_corona.py
#
#						Mar/31/2020
#
import	sys
import	string
import	json
#
# ------------------------------------------------------------------
def parse_proc(dict_aa,ix,cols):
	key = "g%03d" % ix
	unit_aa = {}
	unit_aa['date'] = cols[1]
	unit_aa['age'] = cols[2]
	unit_aa['place'] = cols[3]
	unit_aa['sex'] = cols[4]
	unit_aa['occupation'] = cols[5]
	dict_aa[key] = unit_aa
#
	return	dict_aa
# ------------------------------------------------------------------
sys.stderr.write ("*** 開始 ***\n")
file_in = sys.argv[1]
file_json = sys.argv[2]
sys.stderr.write(file_in + "\n")
sys.stderr.write(file_json + "\n")
#
fp_in = open(file_in,encoding='utf-8')
lines = fp_in.readlines()
fp_in.close()
#
dict_aa = {}
for it in range(len(lines)):
	line = lines[it]
	cols= line[:-1].split ()
	if (4 < len(cols)):
		pos = cols[0].find("例目")
		pos2 = cols[1].find("例目")
		if 0 <= pos:
			it_str = cols[0][:pos]
			ix = int(it_str)
			parse_proc(dict_aa,ix,cols)
		elif 0 <= pos2:
			it_str = cols[1][:pos2]
			ix = int(it_str)
			parse_proc(dict_aa,ix,cols[1:])
#
dict_bb = {}
for key in sorted(dict_aa.keys()):
	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")
# ------------------------------------------------------------------

ホームページ

gunma_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="gunma_patient.js"></script>
<link rel="stylesheet" href="gunma_patient.css">
<title>群馬県の新型コロナウイルス感染症患者の発生状況</title>
</head>
<body>
<blockquote>
<h2>群馬県の新型コロナウイルス感染症患者の発生状況</h2><p />
	<blockquote>
	(3月29日時点)<p />
	</blockquote>
</blockquote>
	<blockquote>
	<div class="contents"></div>
	</blockquote>
</blockquote>
<hr />
データソース
	<blockquote>
	<a href="https://www.pref.gunma.jp/contents/100149743.pdf">群馬県内における新型コロナウイルス感染症発生状況(令和2年3月29日現在)</a><p />
	</blockquote>

<a href="../">Return</a><p />
Mar/31/2020 AM 07:00<p />
</body>
</html>
gunma_patient.css
/* -------------------------------------------------------------- */
/*

	gunma_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;}

/* -------------------------------------------------------------- */
gunma_patient.js
// -----------------------------------------------------------------------
//	gunma_patient.js
//
//					Mar/31/2020
//
// -----------------------------------------------------------------------
jQuery (function ()
{
	jQuery("#outarea_aa").text ("*** gunma_patient *** start ***")

	const file_in = "./data_gunma.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.occupation + "</td>"
			str_out += "</tr>"

			}

		str_out += "</table>"

		jQuery(".contents").html (str_out)
		})

	jQuery("#outarea_hh").text ("*** gunma_patient *** end ***")

})

// -----------------------------------------------------------------------
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?