Ga Min Cha
1 +const soccerAPI = '526fc70a2e8b315e9a960ac4b4764191';
2 +const hostUrl = 'v3.football.api-sports.io';
3 +
4 +var request = require('request');
5 +
6 +var leagueNum = '39';
7 +var seasonNum = '2021';
8 +
9 +const sampleJsonBody = {"get":"teams","parameters":{"league":"39","season":"2021"},"errors":[],"results":20,"paging":{"current":1,"total":1},"response":[{"team":{"id":33,"name":"Manchester United","code":"MUN","country":"England","founded":1878,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/33.png"},"venue":{"id":556,"name":"Old Trafford","address":"Sir Matt Busby Way","city":"Manchester","capacity":76212,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/556.png"}},{"team":{"id":34,"name":"Newcastle","code":"NEW","country":"England","founded":1892,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/34.png"},"venue":{"id":562,"name":"St. James' Park","address":"St. James' Street","city":"Newcastle upon Tyne","capacity":52389,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/562.png"}},{"team":{"id":38,"name":"Watford","code":"WAT","country":"England","founded":1881,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/38.png"},"venue":{"id":596,"name":"Vicarage Road","address":"Vicarage Road","city":"Watford","capacity":22200,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/596.png"}},{"team":{"id":39,"name":"Wolves","code":"WOL","country":"England","founded":1877,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/39.png"},"venue":{"id":600,"name":"Molineux Stadium","address":"Waterloo Road","city":"Wolverhampton, West Midlands","capacity":32050,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/600.png"}},{"team":{"id":40,"name":"Liverpool","code":"LIV","country":"England","founded":1892,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/40.png"},"venue":{"id":550,"name":"Anfield","address":"Anfield Road","city":"Liverpool","capacity":55212,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/550.png"}},{"team":{"id":41,"name":"Southampton","code":"SOU","country":"England","founded":1885,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/41.png"},"venue":{"id":585,"name":"St. Mary's Stadium","address":"Britannia Road","city":"Southampton, Hampshire","capacity":32689,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/585.png"}},{"team":{"id":42,"name":"Arsenal","code":"ARS","country":"England","founded":1886,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/42.png"},"venue":{"id":494,"name":"Emirates Stadium","address":"Queensland Road","city":"London","capacity":60383,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/494.png"}},{"team":{"id":44,"name":"Burnley","code":"BUR","country":"England","founded":1882,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/44.png"},"venue":{"id":512,"name":"Turf Moor","address":"Harry Potts Way","city":"Burnley","capacity":22546,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/512.png"}},{"team":{"id":45,"name":"Everton","code":"EVE","country":"England","founded":1878,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/45.png"},"venue":{"id":8560,"name":"Goodison Park","address":"Goodison Road","city":"Liverpool","capacity":40569,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/8560.png"}},{"team":{"id":46,"name":"Leicester","code":"LEI","country":"England","founded":1884,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/46.png"},"venue":{"id":547,"name":"King Power Stadium","address":"Filbert Way","city":"Leicester, Leicestershire","capacity":34310,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/547.png"}},{"team":{"id":47,"name":"Tottenham","code":"TOT","country":"England","founded":1882,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/47.png"},"venue":{"id":593,"name":"Tottenham Hotspur Stadium","address":"Bill Nicholson Way, 748 High Road","city":"London","capacity":62062,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/593.png"}},{"team":{"id":48,"name":"West Ham","code":"WES","country":"England","founded":1895,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/48.png"},"venue":{"id":598,"name":"London Stadium","address":"Marshgate Lane, Stratford","city":"London","capacity":60000,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/598.png"}},{"team":{"id":49,"name":"Chelsea","code":"CHE","country":"England","founded":1905,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/49.png"},"venue":{"id":519,"name":"Stamford Bridge","address":"Fulham Road","city":"London","capacity":41841,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/519.png"}},{"team":{"id":50,"name":"Manchester City","code":"MAC","country":"England","founded":1880,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/50.png"},"venue":{"id":555,"name":"Etihad Stadium","address":"Rowsley Street","city":"Manchester","capacity":55097,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/555.png"}},{"team":{"id":51,"name":"Brighton","code":"BRI","country":"England","founded":1901,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/51.png"},"venue":{"id":508,"name":"The American Express Community Stadium","address":"Village Way","city":"Falmer, East Sussex","capacity":31800,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/508.png"}},{"team":{"id":52,"name":"Crystal Palace","code":"CRY","country":"England","founded":1905,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/52.png"},"venue":{"id":525,"name":"Selhurst Park","address":"Holmesdale Road","city":"London","capacity":26309,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/525.png"}},{"team":{"id":55,"name":"Brentford","code":"BRE","country":"England","founded":1889,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/55.png"},"venue":{"id":10503,"name":"Brentford Community Stadium","address":"166 Lionel Rd N, Brentford","city":"Brentford, Middlesex","capacity":17250,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/10503.png"}},{"team":{"id":63,"name":"Leeds","code":"LEE","country":"England","founded":1919,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/63.png"},"venue":{"id":546,"name":"Elland Road","address":"Elland Road","city":"Leeds, West Yorkshire","capacity":40204,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/546.png"}},{"team":{"id":66,"name":"Aston Villa","code":"AST","country":"England","founded":1874,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/66.png"},"venue":{"id":495,"name":"Villa Park","address":"Trinity Road","city":"Birmingham","capacity":42788,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/495.png"}},{"team":{"id":71,"name":"Norwich","code":"NOR","country":"England","founded":1902,"national":false,"logo":"https:\/\/media.api-sports.io\/football\/teams\/71.png"},"venue":{"id":565,"name":"Carrow Road","address":"Carrow Road","city":"Norwich, Norfolk","capacity":27606,"surface":"grass","image":"https:\/\/media.api-sports.io\/football\/venues\/565.png"}}]};
10 +var IDNameDict = {};
11 +var responseArr = [];
12 +
13 +// function GetTeamIDsByLeagueID(leagueNum, seasonNum){
14 +// var options = {
15 +// method : 'GET',
16 +// url : 'https://v3.football.api-sports.io/teams?league='+leagueNum+'&season='+seasonNum,
17 +
18 +// headers:{
19 +// 'x-rapidapi-host':hostUrl,
20 +// 'x-rapidapi-key':soccerAPI
21 +// }
22 +// };
23 +
24 +// request(options, function (error, response, body) {
25 +// if (error) throw new Error(error);
26 +// console.log(body);
27 +// });
28 +// }
29 +
30 +responseArr = sampleJsonBody.response;
31 +
32 +function SetTeamIDNameDict(){
33 + responseArr.forEach(teamInfo => IDNameDict[teamInfo.team.name] = teamInfo.team.id);
34 + console.log(Object.keys(IDNameDict));
35 +}
36 +
37 +SetTeamIDNameDict();
38 +
39 +function GetTeamIDByName(teamName){
40 + if(teamName in IDNameDict){
41 + console.log(teamName + " : " + IDNameDict[teamName]);
42 + return IDNameDict[teamName];
43 + }
44 + else{
45 + console.log("There is no team name in this league");
46 + return 0;
47 + }
48 +}
49 +
50 +console.log(GetTeamIDByName('Newcastle'));
51 +GetTeamIDByName('ABC');
...\ No newline at end of file ...\ No newline at end of file
...@@ -508,6 +508,14 @@ ...@@ -508,6 +508,14 @@
508 "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", 508 "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz",
509 "integrity": "sha512-UVU9dibq2JcFWxQPA6KCqj5O42VOmAY3zQUfEKxU0KpTGXwNoCjkX1e13eHNvw/xPynt6pU0rZ1htjWTNTSXsg==" 509 "integrity": "sha512-UVU9dibq2JcFWxQPA6KCqj5O42VOmAY3zQUfEKxU0KpTGXwNoCjkX1e13eHNvw/xPynt6pU0rZ1htjWTNTSXsg=="
510 }, 510 },
511 + "node_modules/JSON": {
512 + "version": "1.0.0",
513 + "resolved": "https://registry.npmjs.org/JSON/-/JSON-1.0.0.tgz",
514 + "integrity": "sha512-6RRYTno2eOUQGPZGboY1p860SC36j0AjiaxghkwuofYSTyD2+XE0Iq13US1by0NiuTEqLyZkXctuvkqFXvE9tA==",
515 + "engines": {
516 + "node": ">= 0.2.0"
517 + }
518 + },
511 "node_modules/json-schema": { 519 "node_modules/json-schema": {
512 "version": "0.4.0", 520 "version": "0.4.0",
513 "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz", 521 "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz",
......
This diff is collapsed. Click to expand it.
1 +{
2 + "author": "Douglas Crockford <douglas@crockford.com> (http://crockford.com)",
3 + "contributors" : ["AJ ONeal <coolaj86@gmail.com> (http://coolaj86.info)"],
4 + "name": "JSON",
5 + "description": "Douglas Crockford's json2.js",
6 + "keywords": ["ender"],
7 + "version": "1.0.0",
8 + "homepage": "http://json.org",
9 + "repository": {
10 + "url": "git://github.com/douglascrockford/JSON-js.git"
11 + },
12 + "main": "json2.js",
13 + "engines": {
14 + "node": ">= 0.2.0"
15 + },
16 + "dependencies": {},
17 + "devDependencies": {}
18 +}
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
10 "license": "ISC", 10 "license": "ISC",
11 "dependencies": { 11 "dependencies": {
12 "express": "^4.18.1", 12 "express": "^4.18.1",
13 + "JSON": "^1.0.0",
13 "request": "^2.88.2" 14 "request": "^2.88.2"
14 } 15 }
15 }, 16 },
...@@ -517,6 +518,14 @@ ...@@ -517,6 +518,14 @@
517 "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", 518 "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz",
518 "integrity": "sha512-UVU9dibq2JcFWxQPA6KCqj5O42VOmAY3zQUfEKxU0KpTGXwNoCjkX1e13eHNvw/xPynt6pU0rZ1htjWTNTSXsg==" 519 "integrity": "sha512-UVU9dibq2JcFWxQPA6KCqj5O42VOmAY3zQUfEKxU0KpTGXwNoCjkX1e13eHNvw/xPynt6pU0rZ1htjWTNTSXsg=="
519 }, 520 },
521 + "node_modules/JSON": {
522 + "version": "1.0.0",
523 + "resolved": "https://registry.npmjs.org/JSON/-/JSON-1.0.0.tgz",
524 + "integrity": "sha512-6RRYTno2eOUQGPZGboY1p860SC36j0AjiaxghkwuofYSTyD2+XE0Iq13US1by0NiuTEqLyZkXctuvkqFXvE9tA==",
525 + "engines": {
526 + "node": ">= 0.2.0"
527 + }
528 + },
520 "node_modules/json-schema": { 529 "node_modules/json-schema": {
521 "version": "0.4.0", 530 "version": "0.4.0",
522 "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz", 531 "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz",
...@@ -1372,6 +1381,11 @@ ...@@ -1372,6 +1381,11 @@
1372 "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", 1381 "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz",
1373 "integrity": "sha512-UVU9dibq2JcFWxQPA6KCqj5O42VOmAY3zQUfEKxU0KpTGXwNoCjkX1e13eHNvw/xPynt6pU0rZ1htjWTNTSXsg==" 1382 "integrity": "sha512-UVU9dibq2JcFWxQPA6KCqj5O42VOmAY3zQUfEKxU0KpTGXwNoCjkX1e13eHNvw/xPynt6pU0rZ1htjWTNTSXsg=="
1374 }, 1383 },
1384 + "JSON": {
1385 + "version": "1.0.0",
1386 + "resolved": "https://registry.npmjs.org/JSON/-/JSON-1.0.0.tgz",
1387 + "integrity": "sha512-6RRYTno2eOUQGPZGboY1p860SC36j0AjiaxghkwuofYSTyD2+XE0Iq13US1by0NiuTEqLyZkXctuvkqFXvE9tA=="
1388 + },
1375 "json-schema": { 1389 "json-schema": {
1376 "version": "0.4.0", 1390 "version": "0.4.0",
1377 "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz", 1391 "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz",
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
14 "license": "ISC", 14 "license": "ISC",
15 "dependencies": { 15 "dependencies": {
16 "express": "^4.18.1", 16 "express": "^4.18.1",
17 + "JSON": "^1.0.0",
17 "request": "^2.88.2" 18 "request": "^2.88.2"
18 } 19 }
19 } 20 }
......