Showing
1 changed file
with
460 additions
and
0 deletions
routes/index3.js
0 → 100644
1 | +var express = require('express'); | ||
2 | +var cheerio = require('cheerio'); | ||
3 | +var request = require('request'); | ||
4 | +const axios = require('axios'); | ||
5 | +//axios 추가 설치된거 확인하기 | ||
6 | +var router = express.Router(); | ||
7 | +var mysql = require('mysql'); | ||
8 | +var client = require('cheerio-httpcli'); | ||
9 | +var passport = require('passport'), | ||
10 | + KakaoStrategy = require('passport-kakao').Strategy; | ||
11 | + | ||
12 | +passport.use(new KakaoStrategy({ | ||
13 | + clientID : 'bd2e610396fb7bbb84cf91a786b3cc72', | ||
14 | + callbackURL :'/auth/login/kakao/callback', | ||
15 | + clientSecret : 'eUtJGtlLoCZJufevp3LKfDP0KOtZUV7R' | ||
16 | + }, | ||
17 | + function(accessToken, refreshToken,params, profile, done){ | ||
18 | + //사용자 정보는 profile에 | ||
19 | + loginByThirdparty(accessToken, refreshToken, profile); | ||
20 | + | ||
21 | + console.log("(!)로그인 : " + profile._json.id+"("+profile._json.properties.nickname +")"); | ||
22 | + //return done(null,profile) | ||
23 | + return done(null, { | ||
24 | + 'user_id': profile._json.id, | ||
25 | + 'nickname': profile._json.properties.nickname | ||
26 | + }); | ||
27 | + } | ||
28 | +)); | ||
29 | + | ||
30 | +// kakao 로그인 | ||
31 | +router.get('/auth/login/kakao', | ||
32 | + // passport.authenticate('kakao',{state: "myStateValue"}) | ||
33 | + passport.authenticate('kakao') | ||
34 | +); | ||
35 | + | ||
36 | +// kakao 로그인 연동 콜백 | ||
37 | +router.get('/auth/login/kakao/callback', | ||
38 | + passport.authenticate('kakao', { | ||
39 | + //session: false, | ||
40 | + successRedirect: '/mytoons', | ||
41 | + failureRedirect: '/' | ||
42 | + }) | ||
43 | +); | ||
44 | + | ||
45 | +function loginByThirdparty(accessToken, refreshToken, profile) { | ||
46 | + //예전 코드는 MySQL 버젼이 맞지 않음 | ||
47 | + // var sql = 'INSERT INTO `user`(id) VALUES(?) ON DUPLICATE KEY(PRIMARY) UPDATE id=(?);' | ||
48 | + var sql = "INSERT INTO `user` (id) VALUES (?) ON DUPLICATE KEY UPDATE id=id"; | ||
49 | + var kid=[profile._json.id]; | ||
50 | + connection.query(sql,kid,function(err,result){ | ||
51 | + if (err) { | ||
52 | + console.log("로그인 쿼리중 에러 : " + err); | ||
53 | + } else { | ||
54 | + console.log("로그인 DB처리 완료!"); | ||
55 | + } | ||
56 | + }); | ||
57 | +} | ||
58 | + | ||
59 | +router.get('/auth/logout/kakao',function (req,res) { | ||
60 | + req.logout(); | ||
61 | + res.redirect('/'); | ||
62 | +}) | ||
63 | + | ||
64 | + | ||
65 | + | ||
66 | +//--------------------------------------------------------------------------------------------------------------------- | ||
67 | +allWebtoons3 = new Array(); | ||
68 | + | ||
69 | +function getAllToons3(){ | ||
70 | + allWebtoonList3 = new Array(); | ||
71 | + | ||
72 | + //2019년 연재 네이버 웹툰 | ||
73 | + const naver2019 = 'https://comic.naver.com/webtoon/period.nhn?period=2019'; | ||
74 | + | ||
75 | + axios.get(naver2019).then(res => { | ||
76 | + if (res.status === 200) { | ||
77 | + let naver2019 = []; | ||
78 | + const $ = cheerio.load(res.data); | ||
79 | + const $toonList = $('#content > div.list_area.daily_img > ul > li'); | ||
80 | + var tn = 2019; | ||
81 | + $toonList.each(function (i) { | ||
82 | + naver2019[i] = { | ||
83 | + title: $(this).find('dl > dt > a').text(), | ||
84 | + img: $(this).find('div > a > img').attr('src'), | ||
85 | + index: $(this).find('li > div > a').attr('href'), | ||
86 | + year : tn | ||
87 | + }; | ||
88 | + }); | ||
89 | + | ||
90 | + const data = naver2019.filter(m => m.title); | ||
91 | + allWebtoonList3.push(data); | ||
92 | + //console.log(allWebtoonList3) | ||
93 | + } | ||
94 | + }, (error) => console.log(error)); | ||
95 | + | ||
96 | + //2018년 연재 네이버 웹툰 | ||
97 | + const naver2018 = 'https://comic.naver.com/webtoon/period.nhn?period=2018'; | ||
98 | + | ||
99 | + axios.get(naver2018).then(res => { | ||
100 | + if (res.status === 200) { | ||
101 | + let naver2018 = []; | ||
102 | + const $ = cheerio.load(res.data); | ||
103 | + const $toonList = $('#content > div.list_area.daily_img > ul > li'); | ||
104 | + var tn = 2018; | ||
105 | + $toonList.each(function (i) { | ||
106 | + naver2018[i] = { | ||
107 | + title: $(this).find('dl > dt > a').text(), | ||
108 | + img: $(this).find('div > a > img').attr('src'), | ||
109 | + index: $(this).find('li > div > a').attr('href'), | ||
110 | + year : tn | ||
111 | + }; | ||
112 | + }); | ||
113 | + | ||
114 | + const data = naver2018.filter(m => m.title); | ||
115 | + allWebtoonList3.push(data); | ||
116 | + //console.log(allWebtoonList3) | ||
117 | + } | ||
118 | + }, (error) => console.log(error)); | ||
119 | + | ||
120 | + //2017년 연재 네이버 웹툰 | ||
121 | + const naver2017 = 'https://comic.naver.com/webtoon/period.nhn?period=2017'; | ||
122 | + | ||
123 | + axios.get(naver2017).then(res => { | ||
124 | + if (res.status === 200) { | ||
125 | + let naver2017 = []; | ||
126 | + const $ = cheerio.load(res.data); | ||
127 | + const $toonList = $('#content > div.list_area.daily_img > ul > li'); | ||
128 | + var tn = 2017; | ||
129 | + $toonList.each(function (i) { | ||
130 | + naver2017[i] = { | ||
131 | + title: $(this).find('dl > dt > a').text(), | ||
132 | + img: $(this).find('div > a > img').attr('src'), | ||
133 | + index: $(this).find('li > div > a').attr('href'), | ||
134 | + year : tn | ||
135 | + }; | ||
136 | + }); | ||
137 | + | ||
138 | + const data = naver2017.filter(m => m.title); | ||
139 | + allWebtoonList3.push(data); | ||
140 | + //console.log(allWebtoonList3) | ||
141 | + } | ||
142 | + }, (error) => console.log(error)); | ||
143 | + | ||
144 | + //2016년 연재 네이버 웹툰 | ||
145 | + const naver2016 = 'https://comic.naver.com/webtoon/period.nhn?period=2016'; | ||
146 | + | ||
147 | + axios.get(naver2016).then(res => { | ||
148 | + if (res.status === 200) { | ||
149 | + let naver2016 = []; | ||
150 | + const $ = cheerio.load(res.data); | ||
151 | + const $toonList = $('#content > div.list_area.daily_img > ul > li'); | ||
152 | + var tn = 2016; | ||
153 | + $toonList.each(function (i) { | ||
154 | + naver2016[i] = { | ||
155 | + title: $(this).find('dl > dt > a').text(), | ||
156 | + img: $(this).find('div > a > img').attr('src'), | ||
157 | + index: $(this).find('li > div > a').attr('href'), | ||
158 | + year : tn | ||
159 | + }; | ||
160 | + }); | ||
161 | + | ||
162 | + const data = naver2016.filter(m => m.title); | ||
163 | + allWebtoonList3.push(data); | ||
164 | + //console.log(allWebtoonList3) | ||
165 | + } | ||
166 | + }, (error) => console.log(error)); | ||
167 | + | ||
168 | + //2015년 연재 네이버 웹툰 | ||
169 | + const naver2015 = 'https://comic.naver.com/webtoon/period.nhn?period=2015'; | ||
170 | + | ||
171 | + axios.get(naver2015).then(res => { | ||
172 | + if (res.status === 200) { | ||
173 | + let naver2015 = []; | ||
174 | + const $ = cheerio.load(res.data); | ||
175 | + const $toonList = $('#content > div.list_area.daily_img > ul > li'); | ||
176 | + var tn = 2015; | ||
177 | + $toonList.each(function (i) { | ||
178 | + naver2015[i] = { | ||
179 | + title: $(this).find('dl > dt > a').text(), | ||
180 | + img: $(this).find('div > a > img').attr('src'), | ||
181 | + index: $(this).find('li > div > a').attr('href'), | ||
182 | + year : tn | ||
183 | + }; | ||
184 | + }); | ||
185 | + | ||
186 | + const data = naver2015.filter(m => m.title); | ||
187 | + allWebtoonList3.push(data); | ||
188 | + //console.log(allWebtoonList3) | ||
189 | + } | ||
190 | + }, (error) => console.log(error)); | ||
191 | +//2014년 연재 네이버 웹툰 | ||
192 | + const naver2014 = 'https://comic.naver.com/webtoon/period.nhn?period=2014'; | ||
193 | + | ||
194 | + axios.get(naver2014).then(res => { | ||
195 | + if (res.status === 200) { | ||
196 | + let naver2014 = []; | ||
197 | + const $ = cheerio.load(res.data); | ||
198 | + const $toonList = $('#content > div.list_area.daily_img > ul > li'); | ||
199 | + var tn = 2014; | ||
200 | + $toonList.each(function (i) { | ||
201 | + naver2014[i] = { | ||
202 | + title: $(this).find('dl > dt > a').text(), | ||
203 | + img: $(this).find('div > a > img').attr('src'), | ||
204 | + index: $(this).find('li > div > a').attr('href'), | ||
205 | + year : tn | ||
206 | + }; | ||
207 | + }); | ||
208 | + | ||
209 | + const data = naver2014.filter(m => m.title); | ||
210 | + allWebtoonList3.push(data); | ||
211 | + //console.log(allWebtoonList3) | ||
212 | + } | ||
213 | + }, (error) => console.log(error)); | ||
214 | + | ||
215 | +//2013년 연재 네이버 웹툰 | ||
216 | + const naver2013 = 'https://comic.naver.com/webtoon/period.nhn?period=2013'; | ||
217 | + | ||
218 | + axios.get(naver2013).then(res => { | ||
219 | + if (res.status === 200) { | ||
220 | + let naver2013 = []; | ||
221 | + const $ = cheerio.load(res.data); | ||
222 | + const $toonList = $('#content > div.list_area.daily_img > ul > li'); | ||
223 | + var tn = 2013; | ||
224 | + $toonList.each(function (i) { | ||
225 | + naver2013[i] = { | ||
226 | + title: $(this).find('dl > dt > a').text(), | ||
227 | + img: $(this).find('div > a > img').attr('src'), | ||
228 | + index: $(this).find('li > div > a').attr('href'), | ||
229 | + year : tn | ||
230 | + }; | ||
231 | + }); | ||
232 | + | ||
233 | + const data = naver2013.filter(m => m.title); | ||
234 | + allWebtoonList3.push(data); | ||
235 | + //console.log(allWebtoonList3) | ||
236 | + } | ||
237 | + }, (error) => console.log(error)); | ||
238 | + | ||
239 | +//2012년 연재 네이버 웹툰 | ||
240 | + const naver2012 = 'https://comic.naver.com/webtoon/period.nhn?period=2012'; | ||
241 | + | ||
242 | + axios.get(naver2012).then(res => { | ||
243 | + if (res.status === 200) { | ||
244 | + let naver2012 = []; | ||
245 | + const $ = cheerio.load(res.data); | ||
246 | + const $toonList = $('#content > div.list_area.daily_img > ul > li'); | ||
247 | + var tn = 2012; | ||
248 | + $toonList.each(function (i) { | ||
249 | + naver2012[i] = { | ||
250 | + title: $(this).find('dl > dt > a').text(), | ||
251 | + img: $(this).find('div > a > img').attr('src'), | ||
252 | + index: $(this).find('li > div > a').attr('href'), | ||
253 | + year : tn | ||
254 | + }; | ||
255 | + }); | ||
256 | + | ||
257 | + const data = naver2012.filter(m => m.title); | ||
258 | + allWebtoonList3.push(data); | ||
259 | + //console.log(allWebtoonList3) | ||
260 | + } | ||
261 | + }, (error) => console.log(error)); | ||
262 | + | ||
263 | +//2011년 연재 네이버 웹툰 | ||
264 | + const naver2011 = 'https://comic.naver.com/webtoon/period.nhn?period=2011'; | ||
265 | + | ||
266 | + axios.get(naver2011).then(res => { | ||
267 | + if (res.status === 200) { | ||
268 | + let naver2011 = []; | ||
269 | + const $ = cheerio.load(res.data); | ||
270 | + const $toonList = $('#content > div.list_area.daily_img > ul > li'); | ||
271 | + var tn = 2011; | ||
272 | + $toonList.each(function (i) { | ||
273 | + naver2011[i] = { | ||
274 | + title: $(this).find('dl > dt > a').text(), | ||
275 | + img: $(this).find('div > a > img').attr('src'), | ||
276 | + index: $(this).find('li > div > a').attr('href'), | ||
277 | + year : tn | ||
278 | + }; | ||
279 | + }); | ||
280 | + | ||
281 | + const data = naver2011.filter(m => m.title); | ||
282 | + allWebtoonList3.push(data); | ||
283 | + //console.log(allWebtoonList3) | ||
284 | + } | ||
285 | + }, (error) => console.log(error)); | ||
286 | + | ||
287 | +//2010년 연재 네이버 웹툰 | ||
288 | + const naver2010 = 'https://comic.naver.com/webtoon/period.nhn?period=2010'; | ||
289 | + | ||
290 | + axios.get(naver2010).then(res => { | ||
291 | + if (res.status === 200) { | ||
292 | + let naver2010 = []; | ||
293 | + const $ = cheerio.load(res.data); | ||
294 | + const $toonList = $('#content > div.list_area.daily_img > ul > li'); | ||
295 | + var tn = 2010; | ||
296 | + $toonList.each(function (i) { | ||
297 | + naver2010[i] = { | ||
298 | + title: $(this).find('dl > dt > a').text(), | ||
299 | + img: $(this).find('div > a > img').attr('src'), | ||
300 | + index: $(this).find('li > div > a').attr('href'), | ||
301 | + year : tn | ||
302 | + }; | ||
303 | + }); | ||
304 | + | ||
305 | + const data = naver2010.filter(m => m.title); | ||
306 | + allWebtoonList3.push(data); | ||
307 | + //console.log(allWebtoonList3) | ||
308 | + } | ||
309 | + }, (error) => console.log(error)); | ||
310 | + | ||
311 | +//2009년 연재 네이버 웹툰 | ||
312 | + const naver2009 = 'https://comic.naver.com/webtoon/period.nhn?period=2009'; | ||
313 | + | ||
314 | + axios.get(naver2009).then(res => { | ||
315 | + if (res.status === 200) { | ||
316 | + let naver2009 = []; | ||
317 | + const $ = cheerio.load(res.data); | ||
318 | + const $toonList = $('#content > div.list_area.daily_img > ul > li'); | ||
319 | + var tn = 2009; | ||
320 | + $toonList.each(function (i) { | ||
321 | + naver2009[i] = { | ||
322 | + title: $(this).find('dl > dt > a').text(), | ||
323 | + img: $(this).find('div > a > img').attr('src'), | ||
324 | + index: $(this).find('li > div > a').attr('href'), | ||
325 | + year : tn | ||
326 | + }; | ||
327 | + }); | ||
328 | + | ||
329 | + const data = naver2009.filter(m => m.title); | ||
330 | + allWebtoonList3.push(data); | ||
331 | + //console.log(allWebtoonList3) | ||
332 | + } | ||
333 | + }, (error) => console.log(error)); | ||
334 | + | ||
335 | +//2008년 연재 네이버 웹툰 | ||
336 | + const naver2008 = 'https://comic.naver.com/webtoon/period.nhn?period=2008'; | ||
337 | + | ||
338 | + axios.get(naver2008).then(res => { | ||
339 | + if (res.status === 200) { | ||
340 | + let naver2008 = []; | ||
341 | + const $ = cheerio.load(res.data); | ||
342 | + const $toonList = $('#content > div.list_area.daily_img > ul > li'); | ||
343 | + var tn = 2008; | ||
344 | + $toonList.each(function (i) { | ||
345 | + naver2008[i] = { | ||
346 | + title: $(this).find('dl > dt > a').text(), | ||
347 | + img: $(this).find('div > a > img').attr('src'), | ||
348 | + index: $(this).find('li > div > a').attr('href'), | ||
349 | + year : tn | ||
350 | + }; | ||
351 | + }); | ||
352 | + | ||
353 | + const data = naver2008.filter(m => m.title); | ||
354 | + allWebtoonList3.push(data); | ||
355 | + //console.log(allWebtoonList3) | ||
356 | + } | ||
357 | + }, (error) => console.log(error)); | ||
358 | + | ||
359 | +//2007년 연재 네이버 웹툰 | ||
360 | + const naver2007 = 'https://comic.naver.com/webtoon/period.nhn?period=2007'; | ||
361 | + | ||
362 | + axios.get(naver2007).then(res => { | ||
363 | + if (res.status === 200) { | ||
364 | + let naver2007 = []; | ||
365 | + const $ = cheerio.load(res.data); | ||
366 | + const $toonList = $('#content > div.list_area.daily_img > ul > li'); | ||
367 | + var tn = 2007; | ||
368 | + $toonList.each(function (i) { | ||
369 | + naver2007[i] = { | ||
370 | + title: $(this).find('dl > dt > a').text(), | ||
371 | + img: $(this).find('div > a > img').attr('src'), | ||
372 | + index: $(this).find('li > div > a').attr('href'), | ||
373 | + year : tn | ||
374 | + }; | ||
375 | + }); | ||
376 | + | ||
377 | + const data = naver2007.filter(m => m.title); | ||
378 | + allWebtoonList3.push(data); | ||
379 | + //console.log(allWebtoonList3) | ||
380 | + } | ||
381 | + }, (error) => console.log(error)); | ||
382 | + | ||
383 | +//2006년 연재 네이버 웹툰 | ||
384 | + const naver2006 = 'https://comic.naver.com/webtoon/period.nhn?period=2006'; | ||
385 | + | ||
386 | + axios.get(naver2006).then(res => { | ||
387 | + if (res.status === 200) { | ||
388 | + let naver2006 = []; | ||
389 | + const $ = cheerio.load(res.data); | ||
390 | + const $toonList = $('#content > div.list_area.daily_img > ul > li'); | ||
391 | + var tn = 2006; | ||
392 | + $toonList.each(function (i) { | ||
393 | + naver2006[i] = { | ||
394 | + title: $(this).find('dl > dt > a').text(), | ||
395 | + img: $(this).find('div > a > img').attr('src'), | ||
396 | + index: $(this).find('li > div > a').attr('href'), | ||
397 | + year : tn | ||
398 | + }; | ||
399 | + }); | ||
400 | + | ||
401 | + const data = naver2006.filter(m => m.title); | ||
402 | + allWebtoonList3.push(data); | ||
403 | + //console.log(allWebtoonList3) | ||
404 | + } | ||
405 | + }, (error) => console.log(error)); | ||
406 | + | ||
407 | +//2005년 연재 네이버 웹툰 | ||
408 | + const naver2005 = 'https://comic.naver.com/webtoon/period.nhn?period=2005'; | ||
409 | + | ||
410 | + axios.get(naver2005).then(res => { | ||
411 | + if (res.status === 200) { | ||
412 | + let naver2005 = []; | ||
413 | + const $ = cheerio.load(res.data); | ||
414 | + const $toonList = $('#content > div.list_area.daily_img > ul > li'); | ||
415 | + var tn = 2005; | ||
416 | + $toonList.each(function (i) { | ||
417 | + naver2005[i] = { | ||
418 | + title: $(this).find('dl > dt > a').text(), | ||
419 | + img: $(this).find('div > a > img').attr('src'), | ||
420 | + index: $(this).find('li > div > a').attr('href'), | ||
421 | + year : tn | ||
422 | + }; | ||
423 | + }); | ||
424 | + | ||
425 | + const data = naver2005.filter(m => m.title); | ||
426 | + allWebtoonList3.push(data); | ||
427 | + //console.log(allWebtoonList3) | ||
428 | + } | ||
429 | + }, (error) => console.log(error)); | ||
430 | + | ||
431 | + allWebtoons3 = allWebtoonList3; | ||
432 | + } | ||
433 | + | ||
434 | + | ||
435 | + | ||
436 | + | ||
437 | + | ||
438 | +getAllToons3(); | ||
439 | +setInterval(getAllToons3,5*60*1000); | ||
440 | + | ||
441 | +/* GET home page. */ | ||
442 | + | ||
443 | +//진아 : list :allWebtoons2.3 해도 되는지??!! | ||
444 | +router.get('/', | ||
445 | + function(req,res,next){ | ||
446 | + if(req.isAuthenticated()){ | ||
447 | + res.redirect('/mytoons'); | ||
448 | + console.log("(!)이미 로그인"); | ||
449 | + }else{ | ||
450 | + console.log("(!)로그인세션 없음"); | ||
451 | + res.render('index',{ | ||
452 | + title: "니툰내툰", | ||
453 | + | ||
454 | + list: allWebtoons3 | ||
455 | + | ||
456 | + }); | ||
457 | + } | ||
458 | + }); | ||
459 | + | ||
460 | +module.exports = router; |
-
Please register or login to post a comment