0
3

More than 3 years have passed since last update.

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

Last updated at Posted at 2020-03-30

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

栃木県の新型コロナウイルス感染症患者の発生状況
tochigi_corona.png

データのソースは栃木県です。

栃木県内 新型コロナウイルス感染症 発生状況

PDF を JSON へ変換

pdftk 20200329corona12reime.pdf cat 1 output out01.pdf
pdftotext -layout out01.pdf
#
./tochigi_corona.py out01.txt data_corona.json
tochigi_corona.py
#! /usr/bin/python
# -*- coding: utf-8 -*-
#
#   tochigi_corona.py
#
#                       Mar/30/2020
#
import  sys
import  json
#
# ------------------------------------------------------------------
def add_data_proc(dict_aa,key_in,name,num):
    key = "p%02d" % int(key_in)
    unit_aa = {}
    unit_aa['name'] = name
    unit_aa['num'] = num
    dict_aa[key] = unit_aa
#
# ------------------------------------------------------------------
def parse_proc(dict_aa,line0,line,line2):
    linex = line[:-1] + line2[:-1]
    cols = linex.split()
    print(len(cols),linex)
    key = "p%02d" % int(cols[0])
    unit_aa = {}
    unit_aa['age'] = cols[1] + " " + cols[2]
    unit_aa['sex'] = cols[3]
    unit_aa['place'] = cols[4]
    if cols[5][0].isdecimal():
        unit_aa['date'] = cols[5]
    else:
        cols0 = line0.split()
        unit_aa['date'] = cols0[0]
    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]
    line0 = ""
    if 0 < it:
        line0 = lines[it - 1]
    line2 = ""
    if it < (len(lines) - 1):
        line2 = lines[it + 1]
    if (5 < len(line)):
        cols= line[:-1].split ()
        if (4 < len(cols)):
            if cols[0].isdecimal():
                parse_proc(dict_aa,line0,line,line2)
#
json_str = json.dumps(dict_aa)
#
fp_out = open(file_json,mode='w',encoding='utf-8')
fp_out.write(json_str)
fp_out.close()
#
sys.stderr.write ("*** 終了 ***\n")
# ------------------------------------------------------------------

ホームページ

tochigi_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="tochigi_patient.js"></script>
<link rel="stylesheet" href="tochigi_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="http://www.pref.tochigi.lg.jp/e04/welfare/hoken-eisei/kansen/r1houdoukansentantou/documents/20200329corona12reime.pdf">栃木県内新型コロナウイルス感染症発生状況</a><p />
    </blockquote>

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

    tochigi_patient.css

                        Mar/30/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;}

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

    const file_in = "./data_corona.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 += "</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 += "</tr>"

            }

        str_out += "</table>"

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

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

})

// -----------------------------------------------------------------------
0
3
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
3