hyunjong

index.js were been clean codes

...@@ -30,7 +30,7 @@ passport.use(new KakaoStrategy({ ...@@ -30,7 +30,7 @@ passport.use(new KakaoStrategy({
30 } 30 }
31 )); 31 ));
32 32
33 -// kakao 로그인, // passport.authenticate('kakao',{state: "myStateValue"}) 33 +// kakao 로그인
34 router.get('/auth/login/kakao', passport.authenticate('kakao')); 34 router.get('/auth/login/kakao', passport.authenticate('kakao'));
35 35
36 // kakao 로그인 연동 콜백 36 // kakao 로그인 연동 콜백
...@@ -68,6 +68,85 @@ function getLatestToon(titleid, day ,cb) { ...@@ -68,6 +68,85 @@ function getLatestToon(titleid, day ,cb) {
68 68
69 } 69 }
70 70
71 +function getDaumToons(_day){
72 + // X요일 다음 웹툰
73 + var day = _day;
74 + var day_name = day;
75 + var daum = `http://webtoon.daum.net/data/pc/webtoon/list_serialized/${day}?timeStamp=1515819276574`;
76 + var site = 'daum';
77 +
78 + client.fetch(daum, {}, function (err, $, res, body) {
79 +
80 + var data = JSON.parse(body);
81 + var list = data["data"];
82 +
83 + list.forEach(function (item, idx) {
84 +
85 + var webtoon_link = 'http://webtoon.daum.net/webtoon/view/' + item.nickname.toString();
86 + var webtoon = {
87 + toon_index : item.id,
88 + name : item.title,
89 + thum_link : item.pcThumbnailImage.url,
90 + webtoon_link : webtoon_link,
91 + week : day_name,
92 + site : site,
93 + latest : 0
94 + };
95 +
96 + allWebtoonList.push(webtoon);
97 + });
98 + });
99 +}
100 +
101 +function getNaverToons(){
102 + var allWeeklyToonsUrl = "http://comic.naver.com/webtoon/weekday.nhn";
103 + request(allWeeklyToonsUrl,function (err, res, html) {
104 + if(!err){
105 + var $ = cheerio.load(html);
106 + var p = Promise.resolve();
107 + var eachs = $(".thumb").each(function (i) {
108 + var week = $(this).parent().parent().prev().attr('class');
109 + var webtoon_link = "http://comic.naver.com" + $(this).children().first().attr('href');
110 + var thumb_link = $(this).children().first().children().first().attr('src');
111 + var name = $(this).next().text();
112 + var titleid = webtoon_link.split('?')[1].split('&')[0].split('=')[1];
113 + var site = 'naver';
114 + var webtoon= {
115 + toon_index: titleid,
116 + name : name,
117 + thum_link : thumb_link,
118 + webtoon_link : webtoon_link,
119 + week : week,
120 + site : site,
121 + latest : 0
122 + };
123 + allWebtoonList.push(webtoon);
124 + });
125 +
126 + p.then(function() {
127 + i = 0;
128 + allWebtoonList.forEach(function (webtoon) {
129 + var sql= "INSERT INTO `toon` (toon_index, name, thum_link, webtoon_link, week, site, latest) VALUES(?) ON DUPLICATE KEY UPDATE latest=latest";
130 + var values=[webtoon.toon_index, webtoon.name, webtoon.thum_link, webtoon.webtoon_link,webtoon.week, webtoon.site, webtoon.latest];
131 +
132 + connection.query(sql,[values],function(err,result){
133 + if (err) {
134 + console.log("웹툰 DB 에러 : " + err);
135 + } else {
136 + console.log("웹툰 DB처리 완료!");
137 + }
138 + });
139 + })
140 + });
141 + }
142 + });
143 +}
144 +
145 +// 구현중
146 +function getTomicsToons(){
147 +
148 +}
149 +
71 // 설명 150 // 설명
72 allWebtoons = new Array(); 151 allWebtoons = new Array();
73 152
...@@ -77,229 +156,31 @@ function getAllToons() { ...@@ -77,229 +156,31 @@ function getAllToons() {
77 allWebtoonList = new Array(); 156 allWebtoonList = new Array();
78 157
79 //월요일 다음 웹툰 158 //월요일 다음 웹툰
80 - var mon='mon'; 159 + getDaumToons('mon');
81 - var mon_name='MON';
82 - var daum = `http://webtoon.daum.net/data/pc/webtoon/list_serialized/${mon}?timeStamp=1515819276574`;
83 - var site = 'daum';
84 -
85 - client.fetch(daum, {}, function (err, $, res, body) {
86 -
87 - var data = JSON.parse(body);
88 - var list = data["data"];
89 -
90 - list.forEach(function (item, idx) {
91 -
92 - var webtoon_link = 'http://webtoon.daum.net/webtoon/view/' + item.nickname.toString();
93 - var webtoon = {
94 - toon_index: item.id,
95 - name: item.title,
96 - thum_link: item.pcThumbnailImage.url,
97 - webtoon_link: webtoon_link,
98 - week :mon_name,
99 - site: site,
100 - latest: 0
101 - };
102 -
103 - allWebtoonList.push(webtoon);
104 - });
105 - });
106 160
107 //화요일 다음 웹툰 161 //화요일 다음 웹툰
108 - var tue='tue'; 162 + getDaumToons('tue');
109 - var tue_name='TUE';
110 - var daum1 = `http://webtoon.daum.net/data/pc/webtoon/list_serialized/${tue}?timeStamp=1515819276574`;
111 -
112 - client.fetch(daum1, {}, function (err, $, res, body) {
113 - var data = JSON.parse(body);
114 - var list = data["data"];
115 -
116 - list.forEach(function(item, idx){
117 -
118 - var webtoon_link='http://webtoon.daum.net/webtoon/view/'+item.nickname.toString();
119 - var webtoon= {
120 - toon_index: item.id,
121 - name : item.title,
122 - thum_link : item.pcThumbnailImage.url,
123 - webtoon_link : webtoon_link,
124 - week : tue_name,
125 - site : site,
126 - latest : 0
127 - };
128 -
129 - allWebtoonList.push(webtoon);
130 - });
131 - });
132 163
133 //수요일 다음 웹툰 164 //수요일 다음 웹툰
134 - var wed='wed'; 165 + getDaumToons('wed');
135 - var wed_name='WED';
136 - var daum2 = `http://webtoon.daum.net/data/pc/webtoon/list_serialized/${wed}?timeStamp=1515819276574`;
137 -
138 - client.fetch(daum2, {}, function (err, $, res, body) {
139 -
140 - var data = JSON.parse(body);
141 - var list = data["data"];
142 -
143 - list.forEach(function(item, idx){
144 -
145 - var webtoon_link='http://webtoon.daum.net/webtoon/view/'+item.nickname.toString();
146 - var webtoon= {
147 - toon_index: item.id,
148 - name : item.title,
149 - thum_link : item.pcThumbnailImage.url,
150 - webtoon_link : webtoon_link,
151 - week : wed_name,
152 - site : site,
153 - latest : 0
154 - };
155 -
156 - allWebtoonList.push(webtoon);
157 - });
158 - });
159 166
160 //목요일 다음 웹툰 167 //목요일 다음 웹툰
161 - var thu='thu'; 168 + getDaumToons('thu');
162 - var daum3 =`http://webtoon.daum.net/data/pc/webtoon/list_serialized/${thu}?timeStamp=1515819276574`;
163 - var thu_name='THU';
164 -
165 - client.fetch(daum3, {}, function (err, $, res, body) {
166 -
167 - var data = JSON.parse(body);
168 - var list = data["data"];
169 -
170 - list.forEach(function(item, idx){
171 -
172 - var webtoon_link='http://webtoon.daum.net/webtoon/view/'+item.nickname.toString();
173 - var webtoon= {
174 - toon_index: item.id,
175 - name : item.title,
176 - thum_link : item.pcThumbnailImage.url,
177 - webtoon_link : webtoon_link,
178 - week : thu_name,
179 - site : site,
180 - latest : 0
181 - };
182 -
183 - allWebtoonList.push(webtoon);
184 - });
185 -
186 - });
187 169
188 //금요일 다음 웹툰 170 //금요일 다음 웹툰
189 - var fri='fri'; 171 + getDaumToons('fri');
190 - var daum4 =`http://webtoon.daum.net/data/pc/webtoon/list_serialized/${fri}?timeStamp=1515819276574`;
191 - var fri_name='FRI';
192 - client.fetch(daum4, {}, function (err, $, res, body) {
193 - var data = JSON.parse(body);
194 - var list = data["data"];
195 - list.forEach(function(item, idx){
196 - var webtoon_link='http://webtoon.daum.net/webtoon/view/'+item.nickname.toString();
197 - var webtoon= {
198 - toon_index: item.id,
199 - name : item.title,
200 - thum_link : item.pcThumbnailImage.url,
201 - webtoon_link : webtoon_link,
202 - week : fri_name,
203 - site : site,
204 - latest : 0
205 - };
206 - allWebtoonList.push(webtoon);
207 - });
208 -
209 - });
210 172
211 //토요일 다음 웹툰 173 //토요일 다음 웹툰
212 - var sat='sat'; 174 + getDaumToons('sat');
213 - var daum5 =`http://webtoon.daum.net/data/pc/webtoon/list_serialized/${sat}?timeStamp=1515819276574`;
214 - var sat_name='SAT';
215 - client.fetch(daum5, {}, function (err, $, res, body) {
216 - var data = JSON.parse(body);
217 - var list = data["data"];
218 - list.forEach(function(item, idx){
219 - var webtoon_link='http://webtoon.daum.net/webtoon/view/'+item.nickname.toString();
220 - var webtoon= {
221 - toon_index: item.id,
222 - name : item.title,
223 - thum_link : item.pcThumbnailImage.url,
224 - webtoon_link : webtoon_link,
225 - week : sat_name,
226 - site : site,
227 - latest : 0
228 - };
229 - allWebtoonList.push(webtoon);
230 - });
231 -
232 - });
233 175
234 //일요일 다음 웹툰 176 //일요일 다음 웹툰
235 - var sun='sun'; 177 + getDaumToons('sun');
236 - var daum6 = `http://webtoon.daum.net/data/pc/webtoon/list_serialized/${sun}?timeStamp=1515819276574`;
237 - var sun_name='SUN';
238 - client.fetch(daum6, {}, function (err, $, res, body) {
239 - var data = JSON.parse(body);
240 - var list = data["data"];
241 - list.forEach(function(item, idx){
242 - var webtoon_link='http://webtoon.daum.net/webtoon/view/'+item.nickname.toString();
243 - var webtoon= {
244 - toon_index: item.id,
245 - name : item.title,
246 - thum_link : item.pcThumbnailImage.url,
247 - webtoon_link : webtoon_link,
248 - week : sun_name,
249 - site : site,
250 - latest : 0
251 - };
252 - allWebtoonList.push(webtoon);
253 - });
254 - });
255 -
256 -
257 -
258 178
259 //네이버 웹툰 179 //네이버 웹툰
260 - var allWeeklyToonsUrl = "http://comic.naver.com/webtoon/weekday.nhn"; 180 + getNaverToons();
261 - request(allWeeklyToonsUrl,function (err, res, html) {
262 - if(!err){
263 - var $ = cheerio.load(html);
264 - var p = Promise.resolve();
265 - var eachs = $(".thumb").each(function (i) {
266 - var week = $(this).parent().parent().prev().attr('class');
267 - var webtoon_link = "http://comic.naver.com" + $(this).children().first().attr('href');
268 - var thumb_link = $(this).children().first().children().first().attr('src');
269 - var name = $(this).next().text();
270 - var titleid = webtoon_link.split('?')[1].split('&')[0].split('=')[1];
271 - var site = 'naver';
272 - var webtoon= {
273 - toon_index: titleid,
274 - name : name,
275 - thum_link : thumb_link,
276 - webtoon_link : webtoon_link,
277 - week : week,
278 - site : site,
279 - latest : 0
280 - };
281 - allWebtoonList.push(webtoon);
282 - });
283 -
284 - p.then(function() {
285 - i = 0;
286 - allWebtoonList.forEach(function (webtoon) {
287 - var sql= "INSERT INTO `toon` (toon_index, name, thum_link, webtoon_link, week, site, latest) VALUES(?) ON DUPLICATE KEY UPDATE latest=latest";
288 - var values=[webtoon.toon_index, webtoon.name, webtoon.thum_link, webtoon.webtoon_link,webtoon.week, webtoon.site, webtoon.latest];
289 -
290 - connection.query(sql,[values],function(err,result){
291 - if (err) {
292 - console.log("웹툰 DB 에러 : " + err);
293 - } else {
294 - console.log("웹툰 DB처리 완료!");
295 - }
296 - });
297 - })
298 - });
299 - }
300 - });
301 181
302 - 182 + //투믹스 웹툰
183 + getTomicsToons();
303 184
304 allWebtoons = allWebtoonList; 185 allWebtoons = allWebtoonList;
305 }; 186 };
...@@ -308,7 +189,7 @@ function getAllToons() { ...@@ -308,7 +189,7 @@ function getAllToons() {
308 getAllToons(); 189 getAllToons();
309 190
310 //5분에 한번 수행 191 //5분에 한번 수행
311 -setInterval(getAllToons,5*60*1000); 192 +setInterval(getAllToons, 5*60*1000);
312 193
313 /* GET home page. */ 194 /* GET home page. */
314 router.get('/', function(req,res,next) { 195 router.get('/', function(req,res,next) {
......