-
Notifications
You must be signed in to change notification settings - Fork 0
/
tba.js
38 lines (27 loc) · 1.12 KB
/
tba.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
//Handles all API Interaction with TheBlueAlliance API
const request = require("request");
const db = require("./my-sql.js");
var tbaId = "jINO6qdzc4xGIZKGxGl6FzY1PzOT29IuOrm0jHoWH21ZHWS6OOjYXhOjl2PI8i2Y";
var baseURL = "https://www.thebluealliance.com/api/v3";
var data;
//Pulls teams and puts them in database
function getTeamsByEvent(eventID){
queryString = baseURL + '/event/' + eventID + '/teams';
request.get( {url : queryString, headers : {"X-TBA-Auth-Key" : tbaId}}, function(error, response, body){
if(error){
console.log("Error getting team info from TBA");
}else{
//Parse returned body to JSON object
data = JSON.parse(body);
//loop through JSON object to get each team number
for(team of data){
//console.log(`${team.team_number}`);
db.insertTeam(`${team.team_number}`, `${team.nickname}`, `${team.rookie_year}`);
console.log("Inserted teams into Database");
};
}
//db.pullTeams();
});
}
//Export functions and Variables
module.exports = { getTeamsByEvent, data };