-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathroutes.js
171 lines (131 loc) · 3.83 KB
/
routes.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
const express = require('express');
const router = express.Router();
var apiKey = process.env.API_KEY;
const request = require('request');
const ejs = require('ejs');
router.get("/", (req, res) => {
res.sendFile(`${__dirname}/index.html`);
});
router.get("/competitions", function (req, res,) {
var options = {
url: "https://api.football-data.org/v2/competitions/",
method: "GET",
headers: {
"X-Auth-Token": apiKey
},
};
request(options, function (error, response, body) {
if (error) {
console.log("ERROR");
}
else {
console.log("SUCCESS");
}
var dataset = JSON.parse(body);
var allData = dataset.count;
res.render("competitions", {
noOfComp: allData,
displayData: dataset
});
})
})
router.get("/competitions/:name", function (req, res,) {
var leaguecode = req.params.name
var options = {
url: "https://api.football-data.org/v2/competitions/" + leaguecode,
method: "GET",
headers: {
"X-Auth-Token": apiKey
},
};
request(options, function (error, response, body) {
if (error) {
console.log("ERROR");
}
else {
console.log("SUCCESS");
}
var dataset = JSON.parse(body);
var seasons = dataset.seasons;
var noOfSeasons = Object.keys(seasons).length;
res.render("particularcompetition", {
displayData: dataset,
seasonCount: noOfSeasons
});
})
})
router.get('/:name/teams', (req, res) => {
let leaguecode = req.params.name;
var options = {
url: "https://api.football-data.org/v2/competitions/" + leaguecode + '/teams',
method: "GET",
headers: {
"X-Auth-Token": apiKey
},
};
request(options, function (error, response, body) {
var leagueData = JSON.parse(body);
var allData = leagueData.count;
res.render("teams", {
no: allData,
disData: leagueData
});
})
})
router.get('/:name/standings', (req, res) => {
let leaguecode = req.params.name;
var options = {
url: "https://api.football-data.org/v2/competitions/" + leaguecode + '/standings',
method: "GET",
headers: {
"X-Auth-Token": apiKey
},
};
request(options, function (error, response, body) {
var standingsData = JSON.parse(body);
var standingCount = standingsData.standings[0].table;
var noOfteams = Object.keys(standingCount).length;
res.render("standings", {
totalTeams: noOfteams,
displayData: standingsData
});
})
})
router.get('/:name/scorers', (req, res) => {
let leaguecode = req.params.name;
console.log(req.query)
var options = {
url: "https://api.football-data.org/v2/competitions/" + leaguecode + '/scorers',
method: "GET",
headers: {
"X-Auth-Token": apiKey
},
};
request(options, function (error, response, body) {
var scorersData = JSON.parse(body);
var count = scorersData.count;
res.render("scorers", {
topScorers: count,
displayData: scorersData
});
})
})
router.get('/teams/:code/:name', (req, res) => {
let teamCode = req.params.code;
console.log(req.query)
var options = {
url: "https://api.football-data.org/v2/teams/" + teamCode,
method: "GET",
headers: {
"X-Auth-Token": apiKey
},
};
request(options, function (error, response, body) {
var teamData = JSON.parse(body);
console.log(teamData);
res.render("particularTeam", {
teamData: teamData
});
})
})
module.exports = router;