-
Notifications
You must be signed in to change notification settings - Fork 0
/
matchReferencer_odds.js
59 lines (50 loc) · 1.68 KB
/
matchReferencer_odds.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
var matchReferencerOddsRun = function(){
var fuzzy = require('fuzzy');
var request = require('request');
var IDs = [];
var findId = [];
var searchId = [];
var idToPush = [];
var getIDforPut = [];
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
console.log("successfully updated");
} else {
console.log("failed " + error);
}
};
//request all matches that are in the database and push them into a search array
request('http://localhost:2403/matches/', function(error, response, body) {
var data = JSON.parse(body);
var matches = {}
var matchNames = []
console.log("Starting...")
for(var i = 0; i < data.length; i++) {
var name = data[i].homeTeamName + data[i].awayTeamName
matchNames.push(name)
matches[name] = data[i]
}
console.log("", matchNames)
console.log("We have " + matchNames.length + " matches...")
//var query = JSON.stringify({'matchReference': {$exists:false}});
request('http://localhost:2403/odds/', function(error, response, body) {
var data = JSON.parse(body);
for(var i = 0; i < data.length; i++) {
var odd = data[i]
var oddID = odd.id
var name = odd.homeTeam + odd.awayTeam
var results = fuzzy.filter(name, matchNames)
if (results[0]) {
var matchID = matches[results[0].string].id
console.log("Found one! Match ID: " + matchID + ", Odd ID: " + oddID)
request({ url: 'http://localhost:2403/odds?id=' + oddID, method: 'PUT', json: {matchReference: matchID}}, callback)
}
else {
//console.log("Nothing found.")
}
}
console.log("Done!")
})
})
}
exports.matchReferencerOddsRun = matchReferencerOddsRun;