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