Skip to content

Instantly share code, notes, and snippets.

@eduardoarandah
Created July 7, 2020 16:35
Show Gist options
  • Save eduardoarandah/9348ded61e5b80121d17aa954659c545 to your computer and use it in GitHub Desktop.
Save eduardoarandah/9348ded61e5b80121d17aa954659c545 to your computer and use it in GitHub Desktop.
Monitor de coronavirus que obtiene datos del sitio oficial de gobierno https://coronavirus.gob.mx/datos/
var fetch = require('node-fetch');
async function activos(claveMunicipio) {
let response = await fetch('https://coronavirus.gob.mx/datos/Overview/info/getInfo.php', {
headers: {
accept: '*/*',
'accept-language': 'es,es-ES;q=0.9,en;q=0.8',
'cache-control': 'no-cache',
'content-type': 'multipart/form-data; boundary=----WebKitFormBoundaryWUKVwTBDWw1CIYBb',
pragma: 'no-cache',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-origin',
},
referrer: 'https://coronavirus.gob.mx/datos/',
referrerPolicy: 'no-referrer-when-downgrade',
body: `------WebKitFormBoundaryWUKVwTBDWw1CIYBb\r\nContent-Disposition: form-data; name="sPatType"\r\n\r\nConfirmados\r\n------WebKitFormBoundaryWUKVwTBDWw1CIYBb\r\nContent-Disposition: form-data; name="cve"\r\n\r\n${claveMunicipio}\r\n------WebKitFormBoundaryWUKVwTBDWw1CIYBb\r\nContent-Disposition: form-data; name="nom"\r\n\r\nMunicipio\r\n------WebKitFormBoundaryWUKVwTBDWw1CIYBb--\r\n`,
method: 'POST',
mode: 'cors',
credentials: 'include',
});
let text = await response.text();
let regexp = /"gsActDIV"\).innerHTML = \((\d+)\)/;
let match = text.match(regexp);
return match[1];
}
// puebla 21114
// xalapa 30087
// http://www3.diputados.gob.mx/camara/content/download/241237/681890/file/Claves%20Entidades%20Federativas%20y%20Municipios%20PEF%202012.pdf
activos(30087).then(res => console.log(`Xalapa: ${res}`));
activos(21114).then(res => console.log(`Puebla: ${res}`));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment