-
Notifications
You must be signed in to change notification settings - Fork 14
/
crawler.js
86 lines (78 loc) · 1.81 KB
/
crawler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const axios = require("axios");
const cheerio = require("cheerio");
const requireDir = require("require-dir");
const sqlite3 = require("sqlite3");
const prompt = require("prompt-sync")();
const moment = require("moment-timezone");
//Create and connect to DB
const db = new sqlite3.Database("./database.db", (err) => {
if (err) {
console.log(err);
}
});
//Import all models
requireDir("./src/models");
//Import controllers
const GameControler = require("./src/controllers/Game");
//Import Crawler
const Crawler = require("./src/crawler");
//Main
const Main = async () => {
console.clear();
console.log("E.g: 28/07/2020");
const dateAnalyseGames = prompt("Choose a date for analyse the games: ");
if (!/^\d{1,2}\/\d{1,2}\/\d{4}$/.test(dateAnalyseGames)) {
console.log("The date is incorrect.");
return false;
}
const CrawlerObj = new Crawler(dateAnalyseGames);
await CrawlerObj.getGamesId();
console.log(`[!] ${CrawlerObj.gamesPrevResult.length} game(s) to analyse`);
await CrawlerObj.analyseGames();
for (let game of CrawlerObj.gamesResult) {
let {
gameId,
gameDate,
homeName,
homeId,
homeAnalyzedGames,
homeGoalsHt,
homeGoalsFt,
homeCornersHt,
homeCornersFt,
awayName,
awayId,
awayAnalyzedGames,
awayGoalsHt,
awayGoalsFt,
awayCornersHt,
awayCornersFt,
} = game;
GameControler.store(
gameId,
gameDate,
homeName,
homeId,
homeAnalyzedGames,
homeGoalsHt,
homeGoalsFt,
homeCornersHt,
homeCornersFt,
awayName,
awayId,
awayAnalyzedGames,
awayGoalsHt,
awayGoalsFt,
awayCornersHt,
awayCornersFt
);
}
console.log("[+] Done");
};
Main();
//Close DB
db.close((err) => {
if (err) {
console.log(err);
}
});