-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
63 lines (58 loc) · 1.82 KB
/
index.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
const fs = require('fs');
const auth = require('./scraping/auth')();
const pages = require('./scraping/pages')();
const stats = require('./stats');
const options = require('./options').parse();
const Matchups = require('./data').fileSystem.Matchups;
const Stats = require('./data').fileSystem.Stats;
const Selections = require('./data').fileSystem.Selections;
const selections = new Selections();
//NPM run useSaved
if (options.useSavedMatchups && options.useSavedStats) {
console.log('using saved matchups and stats');
pages.poolWrite(Matchups.get(), Stats.get(), options.selectionAlgorithm, options.submitSelections)
.then(selectionData => {
selections.set(selectionData);
console.log('all done ; )');
})
.catch(err => {
console.dir(err)
});
}
//NPM start and NPM run populate
else {
if (options.submitSelections) {
console.log('performing live selection');
} else {
console.log('populating matchups and stats');
}
let matchupsStore;
let statsStore;
auth.login()
.then(res => {
console.log(res.message)
}, err => {
console.log('failed to login');
})
.then(stats.get)
.then(data => {
statsStore = data;
Stats.set(data);
}, err => {
console.log('error fetching stats');
})
.then(pages.listRead.bind(pages))
.then(pages.poolRead)
.then(data => {
matchupsStore = data;
Matchups.set(data);
return pages.poolWrite(matchupsStore, statsStore, options.selectionAlgorithm, options.submitSelections);
})
.then(selectionData => {
selections.set(selectionData);
console.log('all done ; )');
})
.catch(err => {
console.dir(err)
});
}