covid-19-py icon indicating copy to clipboard operation
covid-19-py copied to clipboard

Scrape real numbers from ministry website

Open pA1nD opened this issue 4 years ago • 6 comments

Get the real numbers every 5 minutes.

Here is the confirmed cases number:

https://www.mspbs.gov.py/covid-19.php

Screenshot 2020-03-14 at 11 50 21

We still need to get sources for the other three numbers

pA1nD avatar Mar 14 '20 14:03 pA1nD

Must check this repo https://github.com/cabupy/covid19-py It is exactly what you need

juanhuttemann avatar Mar 15 '20 02:03 juanhuttemann

const cheerio = require("cheerio");
const axios = require("axios");
const https = require("https");

/**
 *
 * @param {string} text
 */
const extractNumber = text => {
  let [_, numstr] = text.split(":");
  numstr = numstr.replace("s/g", "");
  const num = Number.parseInt(numstr);
  return num;
};

const fetchCases = async () => {
  const url = "https://www.mspbs.gov.py/covid-19.php";
  const agent = new https.Agent({
    rejectUnauthorized: false
  });

  try {
    const response = await axios.get(url, {
      httpsAgent: agent
    });
    const html = response.data;
    const $ = cheerio.load(html);
    const x = $(
      "body > div > div:nth-child(5) > div > div:nth-child(1) > h4 > font"
    );
    const text = x.text();
    const confirmed = extractNumber(text);
    const deaths = 0;
    const recovered = 0;
    return { confirmed, deaths, recovered, timestamp: new Date() };
  } catch (e) {
    console.error(e);
  }
};

module.exports = {
  fetchCases
};

jmayalag avatar Mar 16 '20 01:03 jmayalag

@jmayalag awesome!

@santiracca can we deploy this in firebase?

pA1nD avatar Mar 16 '20 23:03 pA1nD

https://jmayalag.github.io/covid19-scrape/ You can get the updated json at https://jmayalag.github.io/covid19-scrape/cases.json

It updates every 30 minutes

jmayalag avatar Mar 17 '20 03:03 jmayalag

@jmayalag where do you get the deaths and recovered numbers from?

pA1nD avatar Mar 18 '20 13:03 pA1nD

I don't have them. I should probably change them to NA until the health ministry updates it.

jmayalag avatar Mar 19 '20 12:03 jmayalag