Showing
2 changed files
with
73 additions
and
14 deletions
... | @@ -6,6 +6,7 @@ var bodyParser = require('body-parser'); | ... | @@ -6,6 +6,7 @@ var bodyParser = require('body-parser'); |
6 | var app = express(); // express 객체 저장 | 6 | var app = express(); // express 객체 저장 |
7 | var webcrawl = require('./crawling/Reol'); | 7 | var webcrawl = require('./crawling/Reol'); |
8 | var async = require('async'); | 8 | var async = require('async'); |
9 | +var singer; | ||
9 | 10 | ||
10 | //body-parser 미들웨어 사용 | 11 | //body-parser 미들웨어 사용 |
11 | app.use(bodyParser.urlencoded({extended: false})); | 12 | app.use(bodyParser.urlencoded({extended: false})); |
... | @@ -35,16 +36,28 @@ app.post('/message', function(req,res){ | ... | @@ -35,16 +36,28 @@ app.post('/message', function(req,res){ |
35 | function(callback){ | 36 | function(callback){ |
36 | switch(msg){ | 37 | switch(msg){ |
37 | case 'Reol-Discography' : | 38 | case 'Reol-Discography' : |
39 | + singer = 'Reol' | ||
38 | webcrawl.crawl_Reol('https://namu.wiki/w/%EB%A0%88%EC%98%A4%EB%A3%A8/%EC%9D%8C%EB%B0%98#toc',function(Reol){ | 40 | webcrawl.crawl_Reol('https://namu.wiki/w/%EB%A0%88%EC%98%A4%EB%A3%A8/%EC%9D%8C%EB%B0%98#toc',function(Reol){ |
39 | callback(null,Reol); | 41 | callback(null,Reol); |
40 | }) | 42 | }) |
41 | break; | 43 | break; |
42 | - case '米津玄師-Discography' : | 44 | + default: |
45 | + if(singer == 'Reol'){ | ||
46 | + webcrawl.crawl_Reol('https://namu.wiki/w/%EB%A0%88%EC%98%A4%EB%A3%A8/%EC%9D%8C%EB%B0%98#toc',function(Reol){ | ||
47 | + callback(null,Reol); | ||
48 | + }) | ||
49 | + } | ||
50 | + else if(singer == "Yonezu"){ | ||
43 | 51 | ||
52 | + } | ||
53 | + else | ||
54 | + callback(null,null); | ||
55 | + break; | ||
44 | } | 56 | } |
45 | 57 | ||
46 | }, | 58 | }, |
47 | function(discography, callback){ | 59 | function(discography, callback){ |
60 | + var index = parseInt(msg[0])-1; | ||
48 | switch (msg) { | 61 | switch (msg) { |
49 | case '일본': | 62 | case '일본': |
50 | send = { | 63 | send = { |
... | @@ -53,7 +66,7 @@ app.post('/message', function(req,res){ | ... | @@ -53,7 +66,7 @@ app.post('/message', function(req,res){ |
53 | }, | 66 | }, |
54 | keyboard: { | 67 | keyboard: { |
55 | 'type': 'buttons', | 68 | 'type': 'buttons', |
56 | - 'buttons': ['Reol', '米津玄師', 'yanaginagi', 'ヨルシカ', 'ダズビ', 'Polkadot Stingray', 'Aimyong'] | 69 | + 'buttons': ['Reol', '米津玄師', 'ヨルシカ'] |
57 | } | 70 | } |
58 | 71 | ||
59 | }; | 72 | }; |
... | @@ -66,7 +79,7 @@ app.post('/message', function(req,res){ | ... | @@ -66,7 +79,7 @@ app.post('/message', function(req,res){ |
66 | }, | 79 | }, |
67 | keyboard: { | 80 | keyboard: { |
68 | 'type': 'buttons', | 81 | 'type': 'buttons', |
69 | - 'buttons': ['볼빨간 사춘기', 'MOT', 'Gukkasten', 'ZICO', 'DEAN', 'IU', 'Heize'] | 82 | + 'buttons': ['MOT', 'Gukkasten', 'ZICO'] |
70 | } | 83 | } |
71 | }; | 84 | }; |
72 | break; | 85 | break; |
... | @@ -93,23 +106,42 @@ app.post('/message', function(req,res){ | ... | @@ -93,23 +106,42 @@ app.post('/message', function(req,res){ |
93 | }; | 106 | }; |
94 | break; | 107 | break; |
95 | case 'Reol-Discography' : | 108 | case 'Reol-Discography' : |
96 | - console.log(discography); | ||
97 | send = { | 109 | send = { |
98 | 'message': { | 110 | 'message': { |
99 | 'text': '앨범 목록입니다.' | 111 | 'text': '앨범 목록입니다.' |
100 | }, | 112 | }, |
101 | keyboard: { | 113 | keyboard: { |
102 | - 'type': 'buttons', | 114 | + 'type': 'buttons', |
103 | 'buttons': discography[0].json_album | 115 | 'buttons': discography[0].json_album |
104 | } | 116 | } |
105 | } | 117 | } |
106 | break; | 118 | break; |
107 | - case discography[0].json_album[0]: | 119 | + case discography[0].json_album[index]: |
108 | - send = { | 120 | + var album = '앨범 : ' + discography[0].json_album[index].substr(3); |
109 | - 'message' : { | 121 | + if(singer == 'Reol'){ |
110 | - 'text' : discography[0].json_album[0] + '\n 발매년도 : ' + discography[0].json_year[0] + '\n 수록곡 : \n' + discography[0].json_track[0] | 122 | + send = { |
123 | + 'message' : { | ||
124 | + 'text' : album + '\n발매년도 : ' + discography[0].json_year[index] + '\n수록곡 : \n' + discography[0].json_track[index] | ||
125 | + }, | ||
126 | + keyboard : { | ||
127 | + 'type' : 'buttons', | ||
128 | + 'buttons' : ['Reol-Discography', '초기화면'] | ||
129 | + } | ||
130 | + } | ||
131 | + } | ||
132 | + else if(singer == 'Yonezu'){ | ||
133 | + send = { | ||
134 | + 'message' : { | ||
135 | + 'text' : album + '\n발매년도 : ' + discography[0].json_year[index] + '\n수록곡 : \n' + discography[0].json_track[index] | ||
136 | + }, | ||
137 | + keyboard : { | ||
138 | + 'type' : 'buttons', | ||
139 | + 'buttons' : ['米津玄師-Discography', '초기화면'] | ||
140 | + } | ||
111 | } | 141 | } |
112 | } | 142 | } |
143 | + break; | ||
144 | + | ||
113 | /// 米津玄師 /// | 145 | /// 米津玄師 /// |
114 | case '米津玄師' : | 146 | case '米津玄師' : |
115 | send = { | 147 | send = { |
... | @@ -142,6 +174,18 @@ app.post('/message', function(req,res){ | ... | @@ -142,6 +174,18 @@ app.post('/message', function(req,res){ |
142 | } | 174 | } |
143 | 175 | ||
144 | }; | 176 | }; |
177 | + break; | ||
178 | + case '초기화면' : | ||
179 | + send = { | ||
180 | + 'message' : { | ||
181 | + 'text' : '초기화면으로 돌아갑니다.' | ||
182 | + }, | ||
183 | + keyboard : { | ||
184 | + 'type' : 'buttons', | ||
185 | + 'buttons' : ['한국', '일본'] | ||
186 | + } | ||
187 | + } | ||
188 | + break; | ||
145 | default: | 189 | default: |
146 | break; | 190 | break; |
147 | } | 191 | } | ... | ... |
... | @@ -8,7 +8,7 @@ function crawl_Reol(url,callback){ | ... | @@ -8,7 +8,7 @@ function crawl_Reol(url,callback){ |
8 | 8 | ||
9 | var Reol = new Array(); | 9 | var Reol = new Array(); |
10 | var album, year | 10 | var album, year |
11 | - var album_track = new Array(); | 11 | + var album_track = '' |
12 | var json_album = new Array(), json_year = new Array(), json_track = new Array(); | 12 | var json_album = new Array(), json_year = new Array(), json_track = new Array(); |
13 | $('body > div.content-wrapper > article > div.wiki-content.clearfix > div').each(function (index, ele) { | 13 | $('body > div.content-wrapper > article > div.wiki-content.clearfix > div').each(function (index, ele) { |
14 | for (var i = 1; i <= $('.toc-item').length; i++) { | 14 | for (var i = 1; i <= $('.toc-item').length; i++) { |
... | @@ -23,18 +23,32 @@ function crawl_Reol(url,callback){ | ... | @@ -23,18 +23,32 @@ function crawl_Reol(url,callback){ |
23 | //year 가져오기 | 23 | //year 가져오기 |
24 | year = $('body > div.content-wrapper > article > div.wiki-content.clearfix > div > div:nth-child(' + index + ') > div:nth-child(3) > table > tbody > tr:nth-child(1) > td:nth-child(2)').text(); | 24 | year = $('body > div.content-wrapper > article > div.wiki-content.clearfix > div > div:nth-child(' + index + ') > div:nth-child(3) > table > tbody > tr:nth-child(1) > td:nth-child(2)').text(); |
25 | //track 가져오기 | 25 | //track 가져오기 |
26 | + var track_num = 0; | ||
26 | $('body > div.content-wrapper > article > div.wiki-content.clearfix > div > div:nth-child(' + index + ') > div:nth-child(3) > table > tbody').find('tr').each(function (index, ele) { | 27 | $('body > div.content-wrapper > article > div.wiki-content.clearfix > div > div:nth-child(' + index + ') > div:nth-child(3) > table > tbody').find('tr').each(function (index, ele) { |
27 | var track = $(this).children().eq(1).text(); | 28 | var track = $(this).children().eq(1).text(); |
28 | - if (track != '1' && track != '곡명' && track[4] != '년') | 29 | + if (track != '1' && track != '곡명' && track[4] != '년'){ |
29 | - album_track.push(track) | 30 | + if(track[track.length-1] == 'M') |
31 | + track = track.substr(0,track.length-1); | ||
32 | + if(track[track.length-1] == ']') | ||
33 | + track = track.substr(0,track.length-2); | ||
34 | + track_num++; | ||
35 | + album_track += track_num+'. '+track + '\n'; | ||
36 | + } | ||
30 | }); | 37 | }); |
31 | } | 38 | } |
32 | else { | 39 | else { |
33 | year = $('body > div.content-wrapper > article > div.wiki-content.clearfix > div > div:nth-child(' + index + ') > div:nth-child(4) > table > tbody > tr:nth-child(1) > td:nth-child(2)').text(); | 40 | year = $('body > div.content-wrapper > article > div.wiki-content.clearfix > div > div:nth-child(' + index + ') > div:nth-child(4) > table > tbody > tr:nth-child(1) > td:nth-child(2)').text(); |
41 | + var track_num = 0; | ||
34 | $('body > div.content-wrapper > article > div.wiki-content.clearfix > div > div:nth-child(' + index + ') > div:nth-child(4) > table > tbody').find('tr').each(function (index, ele) { | 42 | $('body > div.content-wrapper > article > div.wiki-content.clearfix > div > div:nth-child(' + index + ') > div:nth-child(4) > table > tbody').find('tr').each(function (index, ele) { |
35 | var track = $(this).children().eq(1).text(); | 43 | var track = $(this).children().eq(1).text(); |
36 | - if (track != '1' && track != '곡명' && track[4] != '년') | 44 | + if (track != '1' && track != '곡명' && track[4] != '년'){ |
37 | - album_track.push(track) | 45 | + if(track[track.length-1] == 'M') |
46 | + track = track.substr(0,track.length-1); | ||
47 | + if(track[track.length-1] == ']') | ||
48 | + track = track.substr(0,track.length-2); | ||
49 | + track_num++; | ||
50 | + album_track += track_num+'. '+track + '\n'; | ||
51 | + } | ||
38 | }); | 52 | }); |
39 | } | 53 | } |
40 | if (year != '') { | 54 | if (year != '') { |
... | @@ -44,6 +58,7 @@ function crawl_Reol(url,callback){ | ... | @@ -44,6 +58,7 @@ function crawl_Reol(url,callback){ |
44 | album_track = []; | 58 | album_track = []; |
45 | } | 59 | } |
46 | }); | 60 | }); |
61 | + Reol.push({ json_album, json_year, json_track }); | ||
47 | callback(Reol); | 62 | callback(Reol); |
48 | }); | 63 | }); |
49 | } | 64 | } | ... | ... |
-
Please register or login to post a comment