This repository has been archived by the owner on Jan 20, 2022. It is now read-only.
forked from ishi720/covid19_aomori_opendata_get
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsickbeds_summary_json_create.js
82 lines (72 loc) · 3.05 KB
/
sickbeds_summary_json_create.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
'use strict';
const fs = require('fs');
const request = require('request-promise');
// 現在の入院患者数の取得
request('https://www.stopcovid19.jp/data/covid19japan.json')
.then(body => {
const obj = JSON.parse(body);
const ncurrentpatients = obj.area[1]['ncurrentpatients'];
const ncurrentpatients_lastUpdate = obj.lastUpdate;
//病床数の取得
// request('https://www.stopcovid19.jp/data/bedforinfection_summary.json')
// .then(body => {
// const obj2 = JSON.parse(body);
// const sumi = obj2.area[1]['sumi'];
// // 出力するデータの作成
// const outputData = {
// 'sickbeds_summary': {
// 'data': {
// '入院患者数': ncurrentpatients,
// '残り病床数': sumi - ncurrentpatients
// },
// 'last_update': ncurrentpatients_lastUpdate.replace(/-/g,'/')
// }
// };
// fs.writeFile('json/sickbeds_summary.json', JSON.stringify(outputData, null, 4), (err, data) => {
// if(err) console.log(err);
// else console.log('sickbeds_summary.json write');
// });
// })
// .catch(error => {
// throw error;
// });
//病床数の取得
request('https://www.stopcovid19.jp/data/covid19japan_beds/latest.json')
.then(body => {
const beds = JSON.parse(body);
// 出力するデータの作成
const outputData = {
'sickbeds_summary': {
'data': {
'入院患者数': ncurrentpatients,
'入院患者受入確保病床': Number(beds[1]['入院患者受入確保病床']),
'宿泊施設受入可能室数': Number(beds[1]['宿泊施設受入可能室数']),
'残り病床数': Number(beds[1]['入院患者受入確保病床']) + Number(beds[1]['宿泊施設受入可能室数']) - ncurrentpatients
},
'last_update': getNewerDate(beds[1]['更新日'].replace(/-/g,'/'), ncurrentpatients_lastUpdate.replace(/-/g,'/'))
}
};
fs.writeFile('json/sickbeds_summary.json', JSON.stringify(outputData, null, 4), (err, data) => {
if(err) console.log(err);
else console.log('sickbeds_summary.json write');
});
})
.catch(error => {
throw error;
});
})
.catch(error => {
throw error;
});
/**
* 新しいほうの日付を取得する
* @param {string} d1 - 日付1
* @param {string} d2 - 日付2
*/
let getNewerDate = (d1, d2) => {
if ( new Date(d1) > new Date(d2)) {
return d1;
} else {
return d2;
}
}