-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.js
62 lines (57 loc) · 1.5 KB
/
server.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
const express = require('express');
const app = express();
const PORT = 3002;
const predictNbaGames = require('./predictNbaGamesToday');
const getSportsbook = require('./scraping/basketballSportsbook');
/// FOR PREDICTING NBA GAMES
app.get('/nba/predict/:anotherDay?', async (req, res) => {
const asJSON = req.query.json !== undefined;
console.log({ asJSON });
try {
const prediction = await predictNbaGames(req.params.anotherDay);
if (asJSON) {
return res.json(prediction);
}
res.send(
[
'<pre>',
JSON.stringify(
prediction,
null,
2
),
'</pre>'
].join('\n')
);
} catch (e) {
res.json({
error: e.message
});
}
});
app.get('/nba/sportsbook', async (req, res) => {
const asJSON = req.query.json !== undefined;
console.log({ asJSON });
try {
const sportsbook = await getSportsbook();
if (asJSON) {
return res.json(sportsbook);
}
res.send(
[
'<pre>',
JSON.stringify(
sportsbook,
null,
2
),
'</pre>'
].join('\n')
);
} catch (e) {
res.json({
error: e.message
});
}
});
app.listen(PORT, () => console.log(`nba predictions on port ${PORT}`));