Showing
9 changed files
with
153 additions
and
45 deletions
getid.js
0 → 100644
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 IDNameArr = []; | ||
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 | +console.log(sampleJsonBody.response); | ||
33 | +function SetTeamIDNameArray(jsonBody){ | ||
34 | + | ||
35 | +} | ||
36 | + | ||
37 | +function GetTeamIDByName(teamName){ | ||
38 | + | ||
39 | +} |
1 | -let sampleJson = '{"id":"2018102191", "name":"Park"}'; | 1 | +let sampleJson = '{"get":"players","parameters":{"id":"276","season":"2019"},"errors":[],"results":1,"paging":{"current":1,"total":1},"response":[{"player":{"id":276,"name":"Neymar da Silva Santos J\u00fanior","firstname":"Neymar","lastname":"da Silva Santos J\u00fanior","age":30,"birth":{"date":"1992-02-05","place":"Mogi das Cruzes","country":"Brazil"},"nationality":"Brazil","height":"175 cm","weight":"68 kg","injured":false,"photo":"https:\/\/media.api-sports.io\/football\/players\/276.png"},"statistics":[{"team":{"id":85,"name":"Paris Saint Germain","logo":"https:\/\/media.api-sports.io\/football\/teams\/85.png"},"league":{"id":61,"name":"Ligue 1","country":"France","logo":"https:\/\/media.api-sports.io\/football\/leagues\/61.png","flag":"https:\/\/media.api-sports.io\/flags\/fr.svg","season":2019},"games":{"appearences":15,"lineups":15,"minutes":1322,"number":null,"position":"Attacker","rating":"8.053333","captain":false},"substitutes":{"in":0,"out":3,"bench":0},"shots":{"total":70,"on":36},"goals":{"total":13,"conceded":null,"assists":6,"saves":null},"passes":{"total":704,"key":39,"accuracy":79},"tackles":{"total":13,"blocks":0,"interceptions":4},"duels":{"total":null,"won":null},"dribbles":{"attempts":143,"success":88,"past":null},"fouls":{"drawn":62,"committed":14},"cards":{"yellow":3,"yellowred":1,"red":0},"penalty":{"won":1,"commited":null,"scored":4,"missed":1,"saved":null}},{"team":{"id":85,"name":"Paris Saint Germain","logo":"https:\/\/media.api-sports.io\/football\/teams\/85.png"},"league":{"id":65,"name":"Coupe de la Ligue","country":"France","logo":"https:\/\/media.api-sports.io\/football\/leagues\/65.png","flag":"https:\/\/media.api-sports.io\/flags\/fr.svg","season":2019},"games":{"appearences":3,"lineups":3,"minutes":300,"number":null,"position":"Attacker","rating":"7.533333","captain":false},"substitutes":{"in":0,"out":0,"bench":0},"shots":{"total":11,"on":5},"goals":{"total":1,"conceded":null,"assists":1,"saves":null},"passes":{"total":144,"key":8,"accuracy":75},"tackles":{"total":3,"blocks":1,"interceptions":1},"duels":{"total":24,"won":15},"dribbles":{"attempts":30,"success":11,"past":null},"fouls":{"drawn":14,"committed":1},"cards":{"yellow":0,"yellowred":0,"red":0},"penalty":{"won":null,"commited":null,"scored":0,"missed":0,"saved":null}},{"team":{"id":85,"name":"Paris Saint Germain","logo":"https:\/\/media.api-sports.io\/football\/teams\/85.png"},"league":{"id":66,"name":"Coupe de France","country":"France","logo":"https:\/\/media.api-sports.io\/football\/leagues\/66.png","flag":"https:\/\/media.api-sports.io\/flags\/fr.svg","season":2019},"games":{"appearences":2,"lineups":2,"minutes":180,"number":null,"position":"Attacker","rating":"7.550000","captain":false},"substitutes":{"in":0,"out":0,"bench":1},"shots":{"total":6,"on":3},"goals":{"total":2,"conceded":null,"assists":null,"saves":null},"passes":{"total":85,"key":4,"accuracy":76},"tackles":{"total":null,"blocks":0,"interceptions":1},"duels":{"total":16,"won":6},"dribbles":{"attempts":16,"success":10,"past":null},"fouls":{"drawn":3,"committed":3},"cards":{"yellow":1,"yellowred":0,"red":0},"penalty":{"won":null,"commited":null,"scored":1,"missed":0,"saved":null}},{"team":{"id":85,"name":"Paris Saint Germain","logo":"https:\/\/media.api-sports.io\/football\/teams\/85.png"},"league":{"id":2,"name":"UEFA Champions League","country":"World","logo":"https:\/\/media.api-sports.io\/football\/leagues\/2.png","flag":null,"season":2019},"games":{"appearences":7,"lineups":6,"minutes":584,"number":null,"position":"Attacker","rating":"7.750000","captain":false},"substitutes":{"in":1,"out":0,"bench":1},"shots":{"total":22,"on":6},"goals":{"total":3,"conceded":null,"assists":4,"saves":null},"passes":{"total":213,"key":16,"accuracy":73},"tackles":{"total":7,"blocks":0,"interceptions":2},"duels":{"total":74,"won":46},"dribbles":{"attempts":57,"success":37,"past":null},"fouls":{"drawn":28,"committed":9},"cards":{"yellow":3,"yellowred":0,"red":0},"penalty":{"won":null,"commited":null,"scored":0,"missed":0,"saved":null}},{"team":{"id":6,"name":"Brazil","logo":"https:\/\/media.api-sports.io\/football\/teams\/6.png"},"league":{"id":10,"name":"Friendlies","country":"World","logo":"https:\/\/media.api-sports.io\/football\/leagues\/10.png","flag":null,"season":2019},"games":{"appearences":5,"lineups":4,"minutes":240,"number":null,"position":"Attacker","rating":null,"captain":false},"substitutes":{"in":1,"out":2,"bench":1},"shots":{"total":null,"on":null},"goals":{"total":1,"conceded":null,"assists":null,"saves":null},"passes":{"total":null,"key":null,"accuracy":null},"tackles":{"total":null,"blocks":null,"interceptions":null},"duels":{"total":null,"won":null},"dribbles":{"attempts":null,"success":null,"past":null},"fouls":{"drawn":null,"committed":null},"cards":{"yellow":0,"yellowred":0,"red":0},"penalty":{"won":null,"commited":null,"scored":null,"missed":null,"saved":null}}]}]}'; |
2 | 2 | ||
3 | -let jJson = JSON.parse(sampleJson); | 3 | +sampleJson = JSON.parse(sampleJson); |
4 | 4 | ||
5 | -console.log(jJson.id); | ||
6 | -console.log(jJson.name); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
5 | +console.log(sampleJson); | ||
6 | + | ||
7 | +let playerName = sampleJson.response[0].player.name.toString() | ||
8 | + | ||
9 | +console.log(playerName); | ||
10 | +console.log(typeof(playerName)); | ||
11 | +console.log(JSON.stringify(sampleJson.response[0].player.name)); | ||
12 | +console.log(typeof(JSON.stringify(playerName))); | ||
13 | +stringJson = sampleJson.toString(); | ||
14 | + | ||
15 | +console.log(sampleJson.toString()); | ||
16 | +console.log(typeof(stringJson)); | ||
... | \ 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", | ... | ... |
node_modules/JSON/json2.js
0 → 100644
This diff is collapsed. Click to expand it.
node_modules/JSON/package.json
0 → 100644
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", | ... | ... |
... | @@ -12,6 +12,7 @@ const sslport = 23023; | ... | @@ -12,6 +12,7 @@ const sslport = 23023; |
12 | var soccer = require('./soccer.js'); | 12 | var soccer = require('./soccer.js'); |
13 | 13 | ||
14 | const bodyParser = require('body-parser'); | 14 | const bodyParser = require('body-parser'); |
15 | +const { EventEmitter } = require('stream'); | ||
15 | var app = express(); | 16 | var app = express(); |
16 | app.use(bodyParser.json()); | 17 | app.use(bodyParser.json()); |
17 | 18 | ||
... | @@ -28,30 +29,30 @@ app.post('/hook', function (req, res) { | ... | @@ -28,30 +29,30 @@ app.post('/hook', function (req, res) { |
28 | console.log('[request message]', eventObj.message); | 29 | console.log('[request message]', eventObj.message); |
29 | console.log("Receive Message : ", eventObj.message.text); | 30 | console.log("Receive Message : ", eventObj.message.text); |
30 | 31 | ||
31 | - console.log(soccer.GetPlayerInfo(276, 2019)); | 32 | + GetPlayerInfo(276, 2019, eventObj); |
32 | - | 33 | + |
33 | - request.post( | 34 | + // request.post( |
34 | - { | 35 | + // { |
35 | - url: TARGET_URL, | 36 | + // url: TARGET_URL, |
36 | - headers: { | 37 | + // headers: { |
37 | - 'Authorization': `Bearer ${TOKEN}` // 인증정보 : channel token 값을 통해 인증. | 38 | + // 'Authorization': `Bearer ${TOKEN}` // 인증정보 : channel token 값을 통해 인증. |
38 | - }, | 39 | + // }, |
39 | - json: { | 40 | + // json: { |
40 | - "replyToken":eventObj.replyToken, // reply token : 누구한테 보낼 것인지?를 판별하기 위해! | 41 | + // "replyToken":eventObj.replyToken, // reply token : 누구한테 보낼 것인지?를 판별하기 위해! |
41 | - "messages":[ | 42 | + // "messages":[ |
42 | - { | 43 | + // { |
43 | - "type":"text", | 44 | + // "type":"text", |
44 | - "text":"Hello, user" | 45 | + // "text":"Hello, user" |
45 | - }, | 46 | + // }, |
46 | - { | 47 | + // { |
47 | - "type":"text", | 48 | + // "type":"text", |
48 | - "text":"May I help you?" | 49 | + // "text":"May I help you?" |
49 | - } | 50 | + // } |
50 | - ] | 51 | + // ] |
51 | - } | 52 | + // } |
52 | - },(error, response, body) => { | 53 | + // },(error, response, body) => { |
53 | - console.log(body); | 54 | + // console.log(body); |
54 | - }); | 55 | + // }); |
55 | 56 | ||
56 | 57 | ||
57 | res.sendStatus(200); | 58 | res.sendStatus(200); |
... | @@ -74,22 +75,16 @@ try { | ... | @@ -74,22 +75,16 @@ try { |
74 | console.log(error); | 75 | console.log(error); |
75 | } | 76 | } |
76 | 77 | ||
77 | -module.exports = { | 78 | +function Reply(eventObj,replyMsg){ |
78 | - StartReply : function(){ | ||
79 | - app.post('/hook', function (req, res) { | ||
80 | 79 | ||
81 | - var eventObj = req.body.events[0]; | 80 | + let replyMsgJSON = JSON.parse(replyMsg); |
82 | - var source = eventObj.source; | ||
83 | - var message = eventObj.message; | ||
84 | 81 | ||
85 | - // request log | 82 | + let playerMsg = JSON.stringify(replyMsgJSON.response[0].player.name); |
86 | - console.log('======================', new Date() ,'======================'); | 83 | + let jsonMsg = JSON.stringify(replyMsgJSON); |
87 | - console.log('[request]', req.body); | ||
88 | - console.log('[request source] ', eventObj.source); | ||
89 | - console.log('[request message]', eventObj.message); | ||
90 | - console.log("Receive Message : ", eventObj.message.text); | ||
91 | 84 | ||
92 | - console.log(soccer.GetPlayerInfo(276, 2019)); | 85 | + console.log(typeof(playerMsg)); |
86 | + console.log("Player Message ", playerMsg); | ||
87 | + console.log("JSON Message ", jsonMsg); | ||
93 | 88 | ||
94 | request.post( | 89 | request.post( |
95 | { | 90 | { |
... | @@ -102,11 +97,11 @@ module.exports = { | ... | @@ -102,11 +97,11 @@ module.exports = { |
102 | "messages":[ | 97 | "messages":[ |
103 | { | 98 | { |
104 | "type":"text", | 99 | "type":"text", |
105 | - "text":"Hello, user" | 100 | + "text":playerMsg |
106 | }, | 101 | }, |
107 | { | 102 | { |
108 | "type":"text", | 103 | "type":"text", |
109 | - "text":"May I help you?" | 104 | + "text":jsonMsg |
110 | } | 105 | } |
111 | ] | 106 | ] |
112 | } | 107 | } |
... | @@ -114,8 +109,22 @@ module.exports = { | ... | @@ -114,8 +109,22 @@ module.exports = { |
114 | console.log(body); | 109 | console.log(body); |
115 | }); | 110 | }); |
116 | 111 | ||
112 | +} | ||
117 | 113 | ||
118 | - res.sendStatus(200); | 114 | +function GetPlayerInfo(playerID, season, eventObj){ |
119 | - }); | 115 | + var request = require('request'); |
116 | + var options = { | ||
117 | + method: 'GET', | ||
118 | + url: 'https://v3.football.api-sports.io/players', | ||
119 | + qs: {id: playerID, season: season}, | ||
120 | + headers: { | ||
121 | + 'x-rapidapi-host': 'v3.football.api-sports.io', | ||
122 | + 'x-rapidapi-key': '526fc70a2e8b315e9a960ac4b4764191' | ||
120 | } | 123 | } |
124 | + }; | ||
125 | + request(options, function (error, response) { | ||
126 | + if (error) throw new Error(error); | ||
127 | + console.log(response.body); | ||
128 | + Reply(eventObj,response.body); | ||
129 | + }); | ||
121 | } | 130 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
splitreply.js
0 → 100644
1 | +let replyMsg = "손흥민, 득점 수, 세계 신기록, 등수, 팀 이름, 오차율, prediction" | ||
2 | + | ||
3 | +function splitReplyMsg(replyMsg){ | ||
4 | + var result = replyMsg.replace(/(\s*)/g, ''); | ||
5 | + result = result.split(','); | ||
6 | + return result; | ||
7 | +} | ||
8 | + | ||
9 | +console.log(splitReplyMsg(replyMsg)); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment