Showing
2 changed files
with
106 additions
and
127 deletions
| ... | @@ -6,7 +6,6 @@ var bodyParser = require('body-parser'); | ... | @@ -6,7 +6,6 @@ var bodyParser = require('body-parser'); |
| 6 | var singer = require('./content') | 6 | var singer = require('./content') |
| 7 | var app = express(); // express 객체 저장 | 7 | var app = express(); // express 객체 저장 |
| 8 | 8 | ||
| 9 | - | ||
| 10 | //body-parser 미들웨어 사용 | 9 | //body-parser 미들웨어 사용 |
| 11 | app.use(bodyParser.urlencoded({extended: false})); | 10 | app.use(bodyParser.urlencoded({extended: false})); |
| 12 | app.use(bodyParser.json()); | 11 | app.use(bodyParser.json()); |
| ... | @@ -33,48 +32,37 @@ app.post('/message', function(req,res){ | ... | @@ -33,48 +32,37 @@ app.post('/message', function(req,res){ |
| 33 | console.log('전달받은 메시지 : ' + msg); | 32 | console.log('전달받은 메시지 : ' + msg); |
| 34 | 33 | ||
| 35 | var send = {}; | 34 | var send = {}; |
| 36 | - function delay(){ | ||
| 37 | - return new Promise(function(resolve, reject){ | ||
| 38 | - switch (msg) { | ||
| 39 | - case '일본': | ||
| 40 | - send = { | ||
| 41 | - 'message': { | ||
| 42 | - 'text': '등록된 가수 목록입니다.' | ||
| 43 | - }, | ||
| 44 | - keyboard: { | ||
| 45 | - 'type': 'buttons', | ||
| 46 | - 'buttons': ['Reol', '米津玄師', 'yanaginagi', 'ヨルシカ', 'ダズビ', 'Polkadot Stingray', 'Aimyong'] | ||
| 47 | - } | ||
| 48 | 35 | ||
| 49 | - }; | 36 | + switch(msg){ |
| 50 | - break; | 37 | + case '일본' : |
| 51 | - case '한국': | 38 | + send = { |
| 52 | - send = { | 39 | + 'message' : { |
| 53 | - 'message': { | 40 | + 'text' : '등록된 가수 목록입니다.' |
| 54 | - 'text': '등록된 가수 목록입니다.' | 41 | + }, |
| 55 | - }, | 42 | + keyboard : { |
| 56 | - keyboard: { | 43 | + 'type' : 'buttons', |
| 57 | - 'type': 'buttons', | 44 | + 'buttons' : ['Reol', '米津玄師', 'yanaginagi', 'ヨルシカ', 'ダズビ', 'Polkadot Stingray', 'Aimyong'] |
| 58 | - 'buttons': ['볼빨간 사춘기', 'MOT', 'Gukkasten', 'ZICO', 'DEAN', 'IU', 'Heize'] | 45 | + } |
| 59 | - } | 46 | + |
| 60 | - }; | 47 | + }; |
| 61 | - break; | 48 | + break; |
| 62 | - default: | 49 | + case '한국' : |
| 63 | - singer.jpSinger(msg).then(function (result) { | 50 | + send = { |
| 64 | - send = result; | 51 | + 'message' : { |
| 65 | - }) | 52 | + 'text' : '등록된 가수 목록입니다.' |
| 66 | - if (send == '') | 53 | + }, |
| 67 | - send = singer.krSinger(msg); | 54 | + keyboard : { |
| 68 | - break; | 55 | + 'type' : 'buttons', |
| 69 | - } | 56 | + 'buttons' : ['볼빨간 사춘기', 'MOT', 'Gukkasten', 'ZICO', 'DEAN', 'IU', 'Heize'] |
| 70 | - if(send){ | 57 | + } |
| 71 | - resolve(send) | 58 | + }; |
| 72 | - } | 59 | + break; |
| 73 | - reject(new Error("Request is failed")); | 60 | + default: |
| 74 | - }); | 61 | + send = singer.jpSinger(msg); |
| 62 | + if(send == '') | ||
| 63 | + send = singer.krSinger(msg); | ||
| 64 | + break; | ||
| 75 | } | 65 | } |
| 76 | - delay().then(function(result){ | 66 | + console.log(send); |
| 77 | - console.log(result); | 67 | + res.json(send); |
| 78 | - res.json(result); | ||
| 79 | - }) | ||
| 80 | }) | 68 | }) |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -2,97 +2,88 @@ var webcrawl = require('./crawling/Reol') | ... | @@ -2,97 +2,88 @@ var webcrawl = require('./crawling/Reol') |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | function jpSinger(msg, discography){ | 4 | function jpSinger(msg, discography){ |
| 5 | - var test; | ||
| 6 | var discography; | 5 | var discography; |
| 7 | var send = {}; | 6 | var send = {}; |
| 8 | - return new Promise(function(resolve, reject){ | 7 | + function delay(discography){ |
| 9 | - function delay(discography) { | 8 | + switch(msg){ |
| 10 | - switch (msg) { | 9 | + case 'Reol' : |
| 11 | - case 'Reol': | 10 | + send = { |
| 12 | - send = { | 11 | + 'message' : { |
| 13 | - 'message': { | 12 | + 'text' : '이름 : Reol(れをる) \n성별 : 여성 \n생년월일 : 1993년 11월 9일 \n혈액형 : AB형', |
| 14 | - 'text': '이름 : Reol(れをる) \n성별 : 여성 \n생년월일 : 1993년 11월 9일 \n혈액형 : AB형', | 13 | + 'photo' : { |
| 15 | - 'photo': { | 14 | + 'url' : 'https://www.reol.jp/images/profile/reol_Aphoto_2.png', |
| 16 | - 'url': 'https://www.reol.jp/images/profile/reol_Aphoto_2.png', | 15 | + 'width' : 1000, |
| 17 | - 'width': 1000, | 16 | + 'height' : 667 |
| 18 | - 'height': 667 | ||
| 19 | - }, | ||
| 20 | - 'message_button': { | ||
| 21 | - 'label': '공식 홈페이지', | ||
| 22 | - 'url': "https://www.reol.jp/" | ||
| 23 | - } | ||
| 24 | }, | 17 | }, |
| 25 | - keyboard: { | 18 | + 'message_button' : { |
| 26 | - 'type': 'buttons', | 19 | + 'label' : '공식 홈페이지', |
| 27 | - 'buttons': ['Reol-Discography'] | 20 | + 'url' : "https://www.reol.jp/" |
| 28 | - } | ||
| 29 | - }; | ||
| 30 | - break; | ||
| 31 | - case 'Reol-Discography': | ||
| 32 | - console.log(discography); | ||
| 33 | - send = { | ||
| 34 | - 'message': { | ||
| 35 | - 'text': '앨범 목록입니다.' | ||
| 36 | - }, | ||
| 37 | - keyboard: { | ||
| 38 | - 'type': 'buttons', | ||
| 39 | - 'buttons': ['a'] | ||
| 40 | } | 21 | } |
| 22 | + }, | ||
| 23 | + keyboard : { | ||
| 24 | + 'type' : 'buttons', | ||
| 25 | + 'buttons' : ['Reol-Discography'] | ||
| 41 | } | 26 | } |
| 42 | - break; | 27 | + }; |
| 43 | - case '米津玄師': | 28 | + break; |
| 44 | - send = { | 29 | + case 'Reol-Discography' : |
| 45 | - 'message': { | 30 | + console.log(discography); |
| 46 | - 'text': '이름 : 米津玄師(Yonezu Kenshi) \n 성별 : 남성 \n생년월일 : 1991년 3월 10일 \n혈액형 : O형', | 31 | + send = { |
| 47 | - 'photo': { | 32 | + 'message': { |
| 48 | - 'url': 'http://reissuerecords.net/rr/wp-content/uploads/flamingo_photo2.jpg', | 33 | + 'text': '앨범 목록입니다.' |
| 49 | - 'width': 1000, | 34 | + }, |
| 50 | - 'height': 667 | 35 | + keyboard: { |
| 51 | - }, | 36 | + 'type': 'buttons', |
| 52 | - 'message_button': { | 37 | + 'buttons': ['a'] |
| 53 | - 'label': '공식 홈페이지', | 38 | + } |
| 54 | - 'url': "http://reissuerecords.net/" | 39 | + } |
| 55 | - } | 40 | + break; |
| 56 | - }, | 41 | + case '米津玄師' : |
| 57 | - keyboard: { | 42 | + send = { |
| 58 | - 'type': 'buttons', | 43 | + 'message' : { |
| 59 | - 'buttons': ['米津玄師-Discography'] | 44 | + 'text' : '이름 : 米津玄師(Yonezu Kenshi) \n 성별 : 남성 \n생년월일 : 1991년 3월 10일 \n혈액형 : O형', |
| 60 | - } | 45 | + 'photo' : { |
| 61 | - }; | 46 | + 'url' : 'http://reissuerecords.net/rr/wp-content/uploads/flamingo_photo2.jpg', |
| 62 | - break; | 47 | + 'width' : 1000, |
| 63 | - case '米津玄師-Discography': | 48 | + 'height' : 667 |
| 64 | - send = { | ||
| 65 | - 'message': { | ||
| 66 | - 'text': 'Album List' | ||
| 67 | }, | 49 | }, |
| 68 | - keyboard: { | 50 | + 'message_button' : { |
| 69 | - 'type': 'buttons', | 51 | + 'label' : '공식 홈페이지', |
| 70 | - 'buttons': ['Reol', '米津玄師', 'yanaginagi', 'ヨルシカ', 'ダズビ', 'Polkadot Stingray', 'Aimyong'] | 52 | + 'url' : "http://reissuerecords.net/" |
| 71 | } | 53 | } |
| 72 | - | 54 | + }, |
| 73 | - }; | 55 | + keyboard : { |
| 74 | - break; | 56 | + 'type' : 'buttons', |
| 75 | - | 57 | + 'buttons' : ['米津玄師-Discography'] |
| 76 | - default: | 58 | + } |
| 77 | - break; | 59 | + }; |
| 78 | - } | 60 | + break; |
| 79 | - return send; | 61 | + case '米津玄師-Discography' : |
| 80 | - } | 62 | + send = { |
| 81 | - webcrawl.crawl_Reol('https://namu.wiki/w/%EB%A0%88%EC%98%A4%EB%A3%A8/%EC%9D%8C%EB%B0%98#toc').then(function (Result) { | 63 | + 'message' : { |
| 82 | - discography = Result; | 64 | + 'text' : 'Album List' |
| 83 | - return function () { | 65 | + }, |
| 84 | - return Result; | 66 | + keyboard : { |
| 85 | - } | 67 | + 'type' : 'buttons', |
| 86 | - }).catch(function (err) { | 68 | + 'buttons' : ['Reol', '米津玄師', 'yanaginagi', 'ヨルシカ', 'ダズビ', 'Polkadot Stingray', 'Aimyong'] |
| 87 | - console.error(err); | 69 | + } |
| 88 | - }).then(function () { | 70 | + |
| 89 | - delay(discography) | 71 | + }; |
| 90 | - }) | 72 | + break; |
| 91 | - if(send) | 73 | + |
| 92 | - resolve(send) | 74 | + default: |
| 93 | - reject(new Error("Request is failed")); | 75 | + break; |
| 94 | - }) | 76 | + } |
| 95 | - | 77 | + } |
| 78 | + webcrawl.crawl_Reol('https://namu.wiki/w/%EB%A0%88%EC%98%A4%EB%A3%A8/%EC%9D%8C%EB%B0%98#toc').then(function(Result){ | ||
| 79 | + discography = Result; | ||
| 80 | + }).catch(function(err){ | ||
| 81 | + console.error(err); | ||
| 82 | + }).then(function(){ | ||
| 83 | + console.log(discography); | ||
| 84 | + delay(discography); | ||
| 85 | + }); | ||
| 86 | + return send; | ||
| 96 | } | 87 | } |
| 97 | 88 | ||
| 98 | function krSinger(msg){ | 89 | function krSinger(msg){ | ... | ... |
-
Please register or login to post a comment