-
Notifications
You must be signed in to change notification settings - Fork 100
/
generate-mss-yaml.js
57 lines (48 loc) · 1.65 KB
/
generate-mss-yaml.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
#!/usr/bin/env node
require('dotenv').config()
const {join} = require('path')
const {readdir, writeFile} = require('fs-extra')
const {extractData} = require('./lib/airtable')
const MSS_PATH = join(__dirname, 'ministere-sante')
async function computeExistingDates() {
const files = await readdir(MSS_PATH)
return files.map(f => f.slice(0, 10))
}
const valuesMap = {
casConfirmes: 'Cas confirmés',
deces: 'Décès à l’hôpital',
decesEhpad: 'Décès en EHPAD et EMS',
hospitalises: 'Hospitalisations',
reanimation: 'En réanimation',
gueris: 'Retours à domicile',
casConfirmesEhpad: 'Cas confirmés EHPAD/EMS',
nouvellesHospitalisations: 'Nouveaux patients hospitalises',
nouvellesReanimations: 'nouveaux patients en reanimation'
}
function getKeyValuesMap(row) {
return Object.keys(valuesMap).filter(key => valuesMap[key] in row && Number.isInteger(row[valuesMap[key]]))
.map(key => ` ${key}: ${row[valuesMap[key]]}`)
.join('\n')
}
async function buildFile(row) {
const date = row.Date
const content = `date: ${date}
source:
nom: Ministère des Solidarités et de la Santé
# Airtable complété par la DGS
donneesNationales:
${getKeyValuesMap(row)}
`
await writeFile(join(MSS_PATH, `${date}.yaml`), content)
console.log(`Nouvelles données du jour : ${date}`)
}
async function main() {
const rows = await extractData('appvqjbgBnxfnGtka', 'Onglet vue d\'ensemble')
const existingDates = await computeExistingDates()
const newRows = rows.filter(r => r.Date && !existingDates.includes(r.Date))
await Promise.all(newRows.map(newRow => buildFile(newRow)))
}
main().catch(error => {
console.error(error)
process.exit(1)
})