43 lines
928 B
JavaScript
43 lines
928 B
JavaScript
const jsonfile = require("jsonfile");
|
|
|
|
const fetch = require("node-fetch");
|
|
const fecha = require("fecha");
|
|
|
|
const { scrapeResults } = require("./scraper");
|
|
|
|
const file = "data/data.json";
|
|
|
|
// https://www.euro-millions.com/results
|
|
|
|
function retrieveNew() {
|
|
console.log("retrieveNew...");
|
|
const now = new Date().getTime();
|
|
|
|
// https://www.euro-millions.com/results/05-02-2019
|
|
|
|
const yesterday = new Date(now - 8.64e7);
|
|
|
|
const ystring = fecha.format(yesterday, "/DD-MM-YYYY");
|
|
|
|
const lotData = jsonfile.readFileSync(file);
|
|
const u = `https://www.euro-millions.com/results${ystring}`;
|
|
|
|
console.log("retrieving:", u);
|
|
|
|
// https://www.euro-millions.com/results/15-02-2019
|
|
|
|
fetch(u)
|
|
.then((res) => res.text())
|
|
.then((body) => {
|
|
const m = scrapeResults(body);
|
|
|
|
console.log(m);
|
|
|
|
lotData.unshift(m);
|
|
|
|
jsonfile.writeFileSync(file, lotData);
|
|
});
|
|
}
|
|
|
|
module.exports = { retrieveNew };
|