박찬수

all commit

const soccerAPI = '526fc70a2e8b315e9a960ac4b4764191';
const hostUrl = 'v3.football.api-sports.io';
var request = require('request');
var leagueNum = '39';
var seasonNum = '2021';
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"}}]};
var IDNameArr = [];
var responseArr = [];
// function GetTeamIDsByLeagueID(leagueNum, seasonNum){
// var options = {
// method : 'GET',
// url : 'https://v3.football.api-sports.io/teams?league='+leagueNum+'&season='+seasonNum,
// headers:{
// 'x-rapidapi-host':hostUrl,
// 'x-rapidapi-key':soccerAPI
// }
// };
// request(options, function (error, response, body) {
// if (error) throw new Error(error);
// console.log(body);
// });
// }
responseArr = sampleJsonBody.response;
console.log(sampleJsonBody.response);
function SetTeamIDNameArray(jsonBody){
}
function GetTeamIDByName(teamName){
}
let sampleJson = '{"id":"2018102191", "name":"Park"}';
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}}]}]}';
let jJson = JSON.parse(sampleJson);
sampleJson = JSON.parse(sampleJson);
console.log(jJson.id);
console.log(jJson.name);
\ No newline at end of file
console.log(sampleJson);
let playerName = sampleJson.response[0].player.name.toString()
console.log(playerName);
console.log(typeof(playerName));
console.log(JSON.stringify(sampleJson.response[0].player.name));
console.log(typeof(JSON.stringify(playerName)));
stringJson = sampleJson.toString();
console.log(sampleJson.toString());
console.log(typeof(stringJson));
\ No newline at end of file
......
......@@ -508,6 +508,14 @@
"resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz",
"integrity": "sha512-UVU9dibq2JcFWxQPA6KCqj5O42VOmAY3zQUfEKxU0KpTGXwNoCjkX1e13eHNvw/xPynt6pU0rZ1htjWTNTSXsg=="
},
"node_modules/JSON": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/JSON/-/JSON-1.0.0.tgz",
"integrity": "sha512-6RRYTno2eOUQGPZGboY1p860SC36j0AjiaxghkwuofYSTyD2+XE0Iq13US1by0NiuTEqLyZkXctuvkqFXvE9tA==",
"engines": {
"node": ">= 0.2.0"
}
},
"node_modules/json-schema": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz",
......
This diff is collapsed. Click to expand it.
{
"author": "Douglas Crockford <douglas@crockford.com> (http://crockford.com)",
"contributors" : ["AJ ONeal <coolaj86@gmail.com> (http://coolaj86.info)"],
"name": "JSON",
"description": "Douglas Crockford's json2.js",
"keywords": ["ender"],
"version": "1.0.0",
"homepage": "http://json.org",
"repository": {
"url": "git://github.com/douglascrockford/JSON-js.git"
},
"main": "json2.js",
"engines": {
"node": ">= 0.2.0"
},
"dependencies": {},
"devDependencies": {}
}
......@@ -10,6 +10,7 @@
"license": "ISC",
"dependencies": {
"express": "^4.18.1",
"JSON": "^1.0.0",
"request": "^2.88.2"
}
},
......@@ -517,6 +518,14 @@
"resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz",
"integrity": "sha512-UVU9dibq2JcFWxQPA6KCqj5O42VOmAY3zQUfEKxU0KpTGXwNoCjkX1e13eHNvw/xPynt6pU0rZ1htjWTNTSXsg=="
},
"node_modules/JSON": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/JSON/-/JSON-1.0.0.tgz",
"integrity": "sha512-6RRYTno2eOUQGPZGboY1p860SC36j0AjiaxghkwuofYSTyD2+XE0Iq13US1by0NiuTEqLyZkXctuvkqFXvE9tA==",
"engines": {
"node": ">= 0.2.0"
}
},
"node_modules/json-schema": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz",
......@@ -1372,6 +1381,11 @@
"resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz",
"integrity": "sha512-UVU9dibq2JcFWxQPA6KCqj5O42VOmAY3zQUfEKxU0KpTGXwNoCjkX1e13eHNvw/xPynt6pU0rZ1htjWTNTSXsg=="
},
"JSON": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/JSON/-/JSON-1.0.0.tgz",
"integrity": "sha512-6RRYTno2eOUQGPZGboY1p860SC36j0AjiaxghkwuofYSTyD2+XE0Iq13US1by0NiuTEqLyZkXctuvkqFXvE9tA=="
},
"json-schema": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz",
......
......@@ -14,6 +14,7 @@
"license": "ISC",
"dependencies": {
"express": "^4.18.1",
"JSON": "^1.0.0",
"request": "^2.88.2"
}
}
......
......@@ -12,6 +12,7 @@ const sslport = 23023;
var soccer = require('./soccer.js');
const bodyParser = require('body-parser');
const { EventEmitter } = require('stream');
var app = express();
app.use(bodyParser.json());
......@@ -28,30 +29,30 @@ app.post('/hook', function (req, res) {
console.log('[request message]', eventObj.message);
console.log("Receive Message : ", eventObj.message.text);
console.log(soccer.GetPlayerInfo(276, 2019));
GetPlayerInfo(276, 2019, eventObj);
request.post(
{
url: TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}` // 인증정보 : channel token 값을 통해 인증.
},
json: {
"replyToken":eventObj.replyToken, // reply token : 누구한테 보낼 것인지?를 판별하기 위해!
"messages":[
{
"type":"text",
"text":"Hello, user"
},
{
"type":"text",
"text":"May I help you?"
}
]
}
},(error, response, body) => {
console.log(body);
});
// request.post(
// {
// url: TARGET_URL,
// headers: {
// 'Authorization': `Bearer ${TOKEN}` // 인증정보 : channel token 값을 통해 인증.
// },
// json: {
// "replyToken":eventObj.replyToken, // reply token : 누구한테 보낼 것인지?를 판별하기 위해!
// "messages":[
// {
// "type":"text",
// "text":"Hello, user"
// },
// {
// "type":"text",
// "text":"May I help you?"
// }
// ]
// }
// },(error, response, body) => {
// console.log(body);
// });
res.sendStatus(200);
......@@ -73,49 +74,57 @@ try {
console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.');
console.log(error);
}
module.exports = {
StartReply : function(){
app.post('/hook', function (req, res) {
var eventObj = req.body.events[0];
var source = eventObj.source;
var message = eventObj.message;
// request log
console.log('======================', new Date() ,'======================');
console.log('[request]', req.body);
console.log('[request source] ', eventObj.source);
console.log('[request message]', eventObj.message);
console.log("Receive Message : ", eventObj.message.text);
console.log(soccer.GetPlayerInfo(276, 2019));
request.post(
{
url: TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}` // 인증정보 : channel token 값을 통해 인증.
function Reply(eventObj,replyMsg){
let replyMsgJSON = JSON.parse(replyMsg);
let playerMsg = JSON.stringify(replyMsgJSON.response[0].player.name);
let jsonMsg = JSON.stringify(replyMsgJSON);
console.log(typeof(playerMsg));
console.log("Player Message ", playerMsg);
console.log("JSON Message ", jsonMsg);
request.post(
{
url: TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}` // 인증정보 : channel token 값을 통해 인증.
},
json: {
"replyToken":eventObj.replyToken, // reply token : 누구한테 보낼 것인지?를 판별하기 위해!
"messages":[
{
"type":"text",
"text":playerMsg
},
json: {
"replyToken":eventObj.replyToken, // reply token : 누구한테 보낼 것인지?를 판별하기 위해!
"messages":[
{
"type":"text",
"text":"Hello, user"
},
{
"type":"text",
"text":"May I help you?"
}
]
{
"type":"text",
"text":jsonMsg
}
},(error, response, body) => {
console.log(body);
});
res.sendStatus(200);
]
}
},(error, response, body) => {
console.log(body);
});
}
}
function GetPlayerInfo(playerID, season, eventObj){
var request = require('request');
var options = {
method: 'GET',
url: 'https://v3.football.api-sports.io/players',
qs: {id: playerID, season: season},
headers: {
'x-rapidapi-host': 'v3.football.api-sports.io',
'x-rapidapi-key': '526fc70a2e8b315e9a960ac4b4764191'
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
Reply(eventObj,response.body);
});
}
\ No newline at end of file
......
let replyMsg = "손흥민, 득점 수, 세계 신기록, 등수, 팀 이름, 오차율, prediction"
function splitReplyMsg(replyMsg){
var result = replyMsg.replace(/(\s*)/g, '');
result = result.split(',');
return result;
}
console.log(splitReplyMsg(replyMsg));
\ No newline at end of file