박찬수

all commit

...@@ -84,8 +84,6 @@ function SetTeamDataDictionary(){ ...@@ -84,8 +84,6 @@ function SetTeamDataDictionary(){
84 IDNameDict[array[i]] = array[i+1]; 84 IDNameDict[array[i]] = array[i+1];
85 } 85 }
86 } 86 }
87 - console.log("SetTeamDataDictionary()");
88 - console.log(IDNameDict);
89 } 87 }
90 88
91 function GetTeamIDByName(teamName){ 89 function GetTeamIDByName(teamName){
...@@ -124,5 +122,11 @@ exports.SetData = function(){ ...@@ -124,5 +122,11 @@ exports.SetData = function(){
124 FindDataFile(); 122 FindDataFile();
125 } 123 }
126 124
127 -FindDataFile(); 125 +exports.SearchLeague = function(){
126 + return 0;
127 +}
128 +
129 +exports.SearchTeam = function(teamName){
130 + return GetTeamIDByName(teamName);
131 +}
128 132
......
...@@ -890,6 +890,11 @@ ...@@ -890,6 +890,11 @@
890 "node": ">=0.8" 890 "node": ">=0.8"
891 } 891 }
892 }, 892 },
893 + "node_modules/tryparse": {
894 + "version": "0.0.2",
895 + "resolved": "https://registry.npmjs.org/tryparse/-/tryparse-0.0.2.tgz",
896 + "integrity": "sha1-uzJwtyAoBNQioeWMcm0fXgLaxJE="
897 + },
893 "node_modules/tunnel-agent": { 898 "node_modules/tunnel-agent": {
894 "version": "0.6.0", 899 "version": "0.6.0",
895 "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", 900 "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz",
......
1 +lib-cov
2 +*.seed
3 +*.log
4 +*.csv
5 +*.dat
6 +*.out
7 +*.pid
8 +*.gz
9 +
10 +pids
11 +logs
12 +results
13 +
14 +npm-debug.log
15 +node_modules/
1 +TryParse
2 +========
3 +
4 +TryParse allows you to test if a value is an integer, a float
5 +
6 +Installation
7 +```bash
8 +npm install tryparse
9 +```
10 +
11 +Usage
12 +```node
13 +var tryparse = require('tryparse')
14 +
15 +// Good values, as good as using parseInt or parseFloat
16 +var myInt = tryparse.int(4)
17 +> 4
18 +var myFloat = tryparse.float(4.5)
19 +> 4.5
20 +
21 +// Bad values, return null
22 +var notInt = tryParse.int('fhjdsk')
23 +> null
24 +var notFloat = tryParse.float('dhgjsjkg')
25 +> null
26 +
27 +// Good values as strings
28 +var myIntString = tryparse.int("4")
29 +> 4
30 +var myFloatString = tryparse.float("4.5")
31 +> 4.5
32 +
33 +```
34 +
35 +Run Tests (requires tap: https://npmjs.org/package/tap)
36 +```bash
37 +npm test
38 +```
1 +function tryparse () {}
2 +
3 +tryparse.prototype.integer = tryparse.prototype.int = function (value) {
4 + return (parseInt(value) == value && parseFloat(value) !== NaN) ? parseInt(value) : null;
5 +}
6 +
7 +tryparse.prototype.float = function (value) {
8 + return (parseFloat(value) == value && parseFloat(value) !== NaN) ? parseFloat(value) : null;
9 +}
10 +
11 +module.exports = new tryparse;
...\ No newline at end of file ...\ No newline at end of file
1 +{
2 + "name": "tryparse",
3 + "version": "0.0.2",
4 + "description": "TryParse allows you to test if a value is an integer, a float",
5 + "main": "index.js",
6 + "scripts": {
7 + "test": "tap ./test"
8 + },
9 + "repository": {
10 + "type": "git",
11 + "url": "git@github.com:MRdNk/TryParse.git"
12 + },
13 + "devDependencies": {
14 + "tap": "0.4.x"
15 + },
16 + "keywords": [
17 + "tryparse"
18 + ],
19 + "author": "mrdnk",
20 + "license": "MIT"
21 +}
1 +var test = require('tap').test
2 +var tryparse = require('../index.js')
3 +test("if a integer is correctly returned", function (t) {
4 + t.equal(tryparse.int(4), 4, "Is Integer")
5 + t.end()
6 +})
7 +
8 +test("if a integer string is correctly returned", function (t) {
9 + t.equal(tryparse.int("4"), 4, "Is Integer string")
10 + t.end()
11 +})
12 +
13 +test("if a float is correctly returned", function (t) {
14 + t.equal(tryparse.float(4.5), 4.5, "Is Float")
15 + t.end()
16 +})
17 +
18 +test("if a float string is correctly returned", function (t) {
19 + t.equal(tryparse.float("4.5"), 4.5, "Is Float string")
20 + t.end()
21 +})
22 +
23 +test("if a non-integer is returned as null on tryparse.int", function (t) {
24 + t.equal(tryparse.int('s'), null, "Is Not Integer")
25 + t.end()
26 +})
27 +
28 +test("if a non-float is return as null on tryparse.float", function (t) {
29 + t.equal(tryparse.float('4q'), null, "Is Not a Float")
30 + t.end()
31 +})
...\ No newline at end of file ...\ No newline at end of file
...@@ -11,7 +11,8 @@ ...@@ -11,7 +11,8 @@
11 "dependencies": { 11 "dependencies": {
12 "express": "^4.18.1", 12 "express": "^4.18.1",
13 "JSON": "^1.0.0", 13 "JSON": "^1.0.0",
14 - "request": "^2.88.2" 14 + "request": "^2.88.2",
15 + "tryparse": "^0.0.2"
15 } 16 }
16 }, 17 },
17 "node_modules/accepts": { 18 "node_modules/accepts": {
...@@ -900,6 +901,11 @@ ...@@ -900,6 +901,11 @@
900 "node": ">=0.8" 901 "node": ">=0.8"
901 } 902 }
902 }, 903 },
904 + "node_modules/tryparse": {
905 + "version": "0.0.2",
906 + "resolved": "https://registry.npmjs.org/tryparse/-/tryparse-0.0.2.tgz",
907 + "integrity": "sha1-uzJwtyAoBNQioeWMcm0fXgLaxJE="
908 + },
903 "node_modules/tunnel-agent": { 909 "node_modules/tunnel-agent": {
904 "version": "0.6.0", 910 "version": "0.6.0",
905 "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", 911 "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz",
...@@ -1663,6 +1669,11 @@ ...@@ -1663,6 +1669,11 @@
1663 "punycode": "^2.1.1" 1669 "punycode": "^2.1.1"
1664 } 1670 }
1665 }, 1671 },
1672 + "tryparse": {
1673 + "version": "0.0.2",
1674 + "resolved": "https://registry.npmjs.org/tryparse/-/tryparse-0.0.2.tgz",
1675 + "integrity": "sha1-uzJwtyAoBNQioeWMcm0fXgLaxJE="
1676 + },
1666 "tunnel-agent": { 1677 "tunnel-agent": {
1667 "version": "0.6.0", 1678 "version": "0.6.0",
1668 "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", 1679 "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz",
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 "dependencies": { 15 "dependencies": {
16 "express": "^4.18.1", 16 "express": "^4.18.1",
17 "JSON": "^1.0.0", 17 "JSON": "^1.0.0",
18 - "request": "^2.88.2" 18 + "request": "^2.88.2",
19 + "tryparse": "^0.0.2"
19 } 20 }
20 } 21 }
......
1 var express = require('express'); 1 var express = require('express');
2 +var tryParse = require('tryparse');
3 +var papago = require('./transmessage.js');
2 const request = require('request'); 4 const request = require('request');
3 const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' // reply api 5 const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' // reply api
4 const TOKEN = 'XOyIf8jsoQKq3b1zqxE4wawAoFU2Hz433AO3w8/ye+i6+2KrXpyfFwY0Dk/xhHQLPgtgPTiEP/m4IRW+SlVhdtzfH6c0Lfdw6nJ95QOugHfNWfviAmn5Uojh8LQJeAy21bvaNMCy11f+qgLSRnXmCgdB04t89/1O/w1cDnyilFU=' 6 const TOKEN = 'XOyIf8jsoQKq3b1zqxE4wawAoFU2Hz433AO3w8/ye+i6+2KrXpyfFwY0Dk/xhHQLPgtgPTiEP/m4IRW+SlVhdtzfH6c0Lfdw6nJ95QOugHfNWfviAmn5Uojh8LQJeAy21bvaNMCy11f+qgLSRnXmCgdB04t89/1O/w1cDnyilFU='
...@@ -30,7 +32,7 @@ app.post('/hook', function (req, res) { ...@@ -30,7 +32,7 @@ app.post('/hook', function (req, res) {
30 console.log('[request message]', eventObj.message); 32 console.log('[request message]', eventObj.message);
31 console.log("Receive Message : ", eventObj.message.text); 33 console.log("Receive Message : ", eventObj.message.text);
32 34
33 - GetPlayerInfo(276, 2019, eventObj); 35 + SelectAPI(eventObj,message.text);
34 36
35 res.sendStatus(200); 37 res.sendStatus(200);
36 }); 38 });
...@@ -40,8 +42,6 @@ try { ...@@ -40,8 +42,6 @@ try {
40 ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'), 42 ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'),
41 key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(), 43 key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(),
42 cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(), 44 cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(),
43 - //key : fs.readFileSync('./rootca.key'),
44 - // cert : fs.readFileSync('./rootca.crt')
45 }; 45 };
46 46
47 HTTPS.createServer(option, app).listen(sslport, () => { 47 HTTPS.createServer(option, app).listen(sslport, () => {
...@@ -74,7 +74,7 @@ function Reply(eventObj,replyMsg){ ...@@ -74,7 +74,7 @@ function Reply(eventObj,replyMsg){
74 "messages":[ 74 "messages":[
75 { 75 {
76 "type":"text", 76 "type":"text",
77 - "text":playerMsg 77 + "text":replyMsg
78 }, 78 },
79 { 79 {
80 "type":"text", 80 "type":"text",
...@@ -85,7 +85,6 @@ function Reply(eventObj,replyMsg){ ...@@ -85,7 +85,6 @@ function Reply(eventObj,replyMsg){
85 },(error, response, body) => { 85 },(error, response, body) => {
86 console.log(body); 86 console.log(body);
87 }); 87 });
88 -
89 } 88 }
90 89
91 function GetPlayerInfo(playerID, season, eventObj){ 90 function GetPlayerInfo(playerID, season, eventObj){
...@@ -105,3 +104,54 @@ function GetPlayerInfo(playerID, season, eventObj){ ...@@ -105,3 +104,54 @@ function GetPlayerInfo(playerID, season, eventObj){
105 Reply(eventObj,response.body); 104 Reply(eventObj,response.body);
106 }); 105 });
107 } 106 }
107 +
108 +
109 +function SelectAPI(replyMsg){
110 + if(tryParse.int(replyMsg) != null){ // 리그 선택
111 + SelectLeague(tryParse.int(replyMsg));
112 + }
113 + else{ // 팀명 입력
114 + console.log(papago.TranslateKRtoEN(replyMsg));
115 + }
116 + Reply(papago.TranslateKRtoEN(replyMsg));
117 +}
118 +
119 +function SelectLeague(inputNum){
120 + let leagueID = 0;
121 + switch(inputNum){
122 + case 1: // 잉글랜드 프리미어리그
123 + leagueID = 39;
124 + break;
125 + case 2: // 스페인 라리가
126 + leagueID = 140;
127 + break;
128 + case 3: // 이탈리아 세리에 A
129 + leagueID = 135;
130 + break;
131 + case 4: // 독일 분데스리가
132 + leagueID = 78;
133 + break;
134 + case 5: // 프랑스 리그앙
135 + leagueID = 61;
136 + break;
137 + case 6: // 포르투칼 프리메라리가
138 + leagueID = 94;
139 + break;
140 + case 7: // UEFA 챔피언스리그
141 + leagueID = 2;
142 + break;
143 + case 8: // UEFA 유로파리그
144 + leagueID = 4;
145 + break;
146 + case 9: // UEFA 컨퍼런스리그
147 + leagueID = 848;
148 + break;
149 + case 10: // 대한민국 K리그
150 + leagueID = 292;
151 + break;
152 + default:
153 + break;
154 + }
155 + console.log("Returned League ID : %d", leagueID);
156 + return leagueID;
157 +}
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -31,8 +31,10 @@ function transMsg(replyMsg){ ...@@ -31,8 +31,10 @@ function transMsg(replyMsg){
31 if(!error && response.statusCode == 200) { 31 if(!error && response.statusCode == 200) {
32 let transMessage = body.message.result.translatedText; 32 let transMessage = body.message.result.translatedText;
33 console.log(transMessage); 33 console.log(transMessage);
34 + return transMessage;
34 } 35 }
35 }); 36 });
37 + return replyMsg;
36 } 38 }
37 39
38 var replyMsg = "선수, 시즌, 순위, 리그, 손흥민, 네이마르, 1등" 40 var replyMsg = "선수, 시즌, 순위, 리그, 손흥민, 네이마르, 1등"
...@@ -54,6 +56,16 @@ function transMsg_toEn(replyMsg){ ...@@ -54,6 +56,16 @@ function transMsg_toEn(replyMsg){
54 if(!error && response.statusCode == 200) { 56 if(!error && response.statusCode == 200) {
55 let transMessage = body.message.result.translatedText; 57 let transMessage = body.message.result.translatedText;
56 console.log(transMessage); 58 console.log(transMessage);
59 + return transMessage;
57 } 60 }
58 }); 61 });
62 + return replyMsg;
63 +}
64 +
65 +exports.TranslateKRtoEN = function(transMsg){
66 + return transMsg_toEn(transMsg);
67 +}
68 +
69 +exports.TranslateENtoKR = function(transMsg){
70 + return transMsg(transMsg);
59 } 71 }
...\ No newline at end of file ...\ No newline at end of file
......