mirror of
https://github.com/franjsco/covid19-campania
synced 2025-02-26 16:18:17 +01:00
Modificate funzioni per il recupero dei dati
This commit is contained in:
parent
b430292d21
commit
a9d402ab7e
10
package-lock.json
generated
10
package-lock.json
generated
@ -4029,11 +4029,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/csstype/-/csstype-2.6.9.tgz",
|
"resolved": "https://registry.npmjs.org/csstype/-/csstype-2.6.9.tgz",
|
||||||
"integrity": "sha512-xz39Sb4+OaTsULgUERcCk+TJj8ylkL4aSVDQiX/ksxbELSqwkgt4d4RD7fovIdgJGSuNYqwZEiVjYY5l0ask+Q=="
|
"integrity": "sha512-xz39Sb4+OaTsULgUERcCk+TJj8ylkL4aSVDQiX/ksxbELSqwkgt4d4RD7fovIdgJGSuNYqwZEiVjYY5l0ask+Q=="
|
||||||
},
|
},
|
||||||
"csvjson-csv2json": {
|
|
||||||
"version": "5.0.6",
|
|
||||||
"resolved": "https://registry.npmjs.org/csvjson-csv2json/-/csvjson-csv2json-5.0.6.tgz",
|
|
||||||
"integrity": "sha512-to9QlVI4yQFPzSqi6XZ97lULKs5m3K8hlE/UkbvKSw81FfDwgV9MUtSbHFJ4SRT4IA7UPkuW2EqsH/MWN5YRow=="
|
|
||||||
},
|
|
||||||
"cyclist": {
|
"cyclist": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/cyclist/-/cyclist-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/cyclist/-/cyclist-1.0.1.tgz",
|
||||||
@ -4083,11 +4078,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"date-fns": {
|
|
||||||
"version": "2.11.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.11.0.tgz",
|
|
||||||
"integrity": "sha512-8P1cDi8ebZyDxUyUprBXwidoEtiQAawYPGvpfb+Dg0G6JrQ+VozwOmm91xYC0vAv1+0VmLehEPb+isg4BGUFfA=="
|
|
||||||
},
|
|
||||||
"debug": {
|
"debug": {
|
||||||
"version": "4.1.1",
|
"version": "4.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
|
||||||
|
@ -11,8 +11,6 @@
|
|||||||
"@testing-library/user-event": "^7.2.1",
|
"@testing-library/user-event": "^7.2.1",
|
||||||
"axios": "^0.19.2",
|
"axios": "^0.19.2",
|
||||||
"bootstrap": "^4.4.1",
|
"bootstrap": "^4.4.1",
|
||||||
"csvjson-csv2json": "^5.0.6",
|
|
||||||
"date-fns": "^2.11.0",
|
|
||||||
"prop-types": "^15.7.2",
|
"prop-types": "^15.7.2",
|
||||||
"react": "^16.13.0",
|
"react": "^16.13.0",
|
||||||
"react-bootstrap": "^1.0.0-beta.17",
|
"react-bootstrap": "^1.0.0-beta.17",
|
||||||
|
@ -1,13 +1,8 @@
|
|||||||
// import axios from 'axios';
|
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import csv2json from 'csvjson-csv2json';
|
|
||||||
|
|
||||||
import { format, addDays, getHours } from 'date-fns';
|
const getJsonRegioni = async () => {
|
||||||
|
const url = 'https://raw.githubusercontent.com/pcm-dpc/COVID-19/master/dati-json/';
|
||||||
|
const filename = 'dpc-covid19-ita-regioni-latest.json';
|
||||||
const getCSVRegionifromRepository = async (date) => {
|
|
||||||
const url = 'https://raw.githubusercontent.com/pcm-dpc/COVID-19/master/dati-regioni/';
|
|
||||||
const filename = `dpc-covid19-ita-regioni-${format(date, 'yyyyMMdd')}.csv`;
|
|
||||||
const finalURL = `${url + filename}`;
|
const finalURL = `${url + filename}`;
|
||||||
let result;
|
let result;
|
||||||
|
|
||||||
@ -22,35 +17,11 @@ const getCSVRegionifromRepository = async (date) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const convertCSVtoJSON = (csv) => {
|
|
||||||
if (!csv) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return csv2json(csv, { parseNumbers: true });
|
|
||||||
};
|
|
||||||
|
|
||||||
const getData = async () => {
|
const getData = async () => {
|
||||||
const actualDate = new Date();
|
const nomeRegione = 'Campania';
|
||||||
const previousDate = addDays(actualDate, -1);
|
|
||||||
const hour = getHours(actualDate);
|
|
||||||
let result;
|
|
||||||
|
|
||||||
// preleva il CSV con data attuale solamente se sono passate le 18
|
const datiRegione = await getJsonRegioni();
|
||||||
if (hour >= 18) {
|
const result = datiRegione.find((regione) => regione.denominazione_regione === nomeRegione);
|
||||||
result = await getCSVRegionifromRepository(actualDate);
|
|
||||||
}
|
|
||||||
|
|
||||||
// preleva il CSV con data precedente qualora non fosse stato trovato quello attuale
|
|
||||||
if (!result) {
|
|
||||||
result = await getCSVRegionifromRepository(previousDate);
|
|
||||||
}
|
|
||||||
|
|
||||||
// converte il CSV in JSON e filtra i dati per la regione Campania
|
|
||||||
if (result) {
|
|
||||||
const tmpJSON = convertCSVtoJSON(result);
|
|
||||||
result = tmpJSON.find((d) => d.denominazione_regione === 'Campania');
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user