updated data and fixed retriever

This commit is contained in:
Martin Donnelly 2021-01-02 19:30:30 +00:00
parent 1995c45823
commit 0b3e254bb7
5 changed files with 31 additions and 31 deletions

32
app.js
View File

@ -1,24 +1,22 @@
const loader = require('./libs/loader');
const lot = require('./libs/lot');
const lotv2 = require('./libs/lotV2');
const pusher = require('./libs/pusher');
const log4js = require('log4js');
const loader = require("./libs/loader");
const lot = require("./libs/lot");
const lotv2 = require("./libs/lotV2");
const pusher = require("./libs/pusher");
const log4js = require("log4js");
const logger = log4js.getLogger();
const cron = require('node-cron');
const cron = require("node-cron");
const {retrieveNew} = require('./libs/retriever');
const { retrieveNew } = require("./libs/retriever");
logger.level = 'debug';
logger.level = "debug";
function run(data) {
const v1 = lot.calculate(data);
const v2 = lotv2.calculate(data);
const msg =
`V2: ${v2} stars: ${v1.mainstars}
const msg = `V2: ${v2} stars: ${v1.mainstars}
V1: ${v1.mainline} stars: ${v1.mainstars}
Other: ${v1.otherLine} stars: ${v1.otherStars}
Other: ${v1.otherLine} stars: ${v1.otherStars}
`;
pusher.push(msg);
@ -27,21 +25,21 @@ Other: ${v1.otherLine} stars: ${v1.otherStars}
}
function go() {
logger.info('GO!');
logger.info("GO!");
loader.load(run);
retrieveNew();
}
cron.schedule('10 15 * * 2,5', () => {
cron.schedule("10 15 * * 2,5", () => {
go();
return -1;
});
cron.schedule('45 9 * * 3,6', () => {
cron.schedule("45 9 * * 3,6", () => {
retrieveNew();
return -1;
});
logger.info('Lot V3 started...');
logger.info("Lot V3 started...");

File diff suppressed because one or more lines are too long

View File

@ -1,33 +1,34 @@
const jsonfile = require('jsonfile');
const jsonfile = require("jsonfile");
const fetch = require('node-fetch');
const fecha = require('fecha');
const fetch = require("node-fetch");
const fecha = require("fecha");
const { scrapeResults } = require('./scraper');
const { scrapeResults } = require("./scraper");
const file = 'data/data.json';
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.64e+7));
const yesterday = new Date(now - 8.64e7);
const ystring = fecha.format(yesterday, '/DD-MM-YYYY');
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);
console.log("retrieving:", u);
// https://www.euro-millions.com/results/15-02-2019
fetch(u)
.then(res => res.text())
.then(body => {
.then((res) => res.text())
.then((body) => {
const m = scrapeResults(body);
console.log(m);

View File

@ -16,9 +16,9 @@ function scrapeResults(html) {
outArray.push(fecha.format(newDate, 'YYYY-MM-DD'));
const cells = $('#jsBallOrderCell li');
const cells = $('#ballsAscending li');
if ($(cells).length > 0)
if ($(cells).length > 0)
cells.each((i, item) => {
outArray.push(parseInt($(item).text(), 10));

View File

@ -5,7 +5,8 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node lot.js"
"start": "node lot.js",
"retrieve": "node app.js"
},
"author": "",
"license": "ISC",