Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrape real numbers from ministry website #10

Open
pA1nD opened this issue Mar 14, 2020 · 6 comments
Open

Scrape real numbers from ministry website #10

pA1nD opened this issue Mar 14, 2020 · 6 comments
Assignees

Comments

@pA1nD
Copy link
Member

pA1nD commented Mar 14, 2020

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

@juanhuttemann
Copy link

juanhuttemann commented Mar 15, 2020

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

@jmayalag
Copy link
Contributor

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
};

@pA1nD
Copy link
Member Author

pA1nD commented Mar 16, 2020

@jmayalag awesome!

@santiracca can we deploy this in firebase?

@jmayalag
Copy link
Contributor

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

@pA1nD
Copy link
Member Author

pA1nD commented Mar 18, 2020

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

@jmayalag
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants