index.js
23.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
var express = require('express');
var cheerio = require('cheerio');
var request = require('request');
const axios = require('axios');
//axios 추가 설치된거 확인하기
var router = express.Router();
var mysql = require('mysql');
var client = require('cheerio-httpcli');
var passport = require('passport'),
KakaoStrategy = require('passport-kakao').Strategy;
passport.use(new KakaoStrategy({
clientID : 'bd2e610396fb7bbb84cf91a786b3cc72',
callbackURL :'/auth/login/kakao/callback',
clientSecret : 'eUtJGtlLoCZJufevp3LKfDP0KOtZUV7R'
},
function(accessToken, refreshToken,params, profile, done){
//사용자 정보는 profile에
loginByThirdparty(accessToken, refreshToken, profile);
console.log("(!)로그인 : " + profile._json.id+"("+profile._json.properties.nickname +")");
//return done(null,profile)
return done(null, {
'user_id': profile._json.id,
'nickname': profile._json.properties.nickname
});
}
));
// kakao 로그인
router.get('/auth/login/kakao',
// passport.authenticate('kakao',{state: "myStateValue"})
passport.authenticate('kakao')
);
// kakao 로그인 연동 콜백
router.get('/auth/login/kakao/callback',
passport.authenticate('kakao', {
//session: false,
successRedirect: '/mytoons',
failureRedirect: '/'
})
);
function loginByThirdparty(accessToken, refreshToken, profile) {
//예전 코드는 MySQL 버젼이 맞지 않음
// var sql = 'INSERT INTO `user`(id) VALUES(?) ON DUPLICATE KEY(PRIMARY) UPDATE id=(?);'
var sql = "INSERT INTO `user` (id) VALUES (?) ON DUPLICATE KEY UPDATE id=id";
var kid=[profile._json.id];
connection.query(sql,kid,function(err,result){
if (err) {
console.log("로그인 쿼리중 에러 : " + err);
} else {
console.log("로그인 DB처리 완료!");
}
});
}
router.get('/auth/logout/kakao',function (req,res) {
req.logout();
res.redirect('/');
})
allWebtoons = new Array();
function getLatestToon(titleid, day ,cb) {
}
function getAllToons() {
allWebtoonList = new Array();
//월요일 다음 웹툰
var mon='mon';
var mon_name='MON';
var daum = `http://webtoon.daum.net/data/pc/webtoon/list_serialized/${mon}?timeStamp=1515819276574`;
var site = 'daum';
client.fetch(daum, {}, function (err, $, res, body) {
var data = JSON.parse(body);
var list = data["data"];
list.forEach(function (item, idx) {
var webtoon_link = 'http://webtoon.daum.net/webtoon/view/' + item.nickname.toString();
var webtoon = {
toon_index: item.id,
name: item.title,
thum_link: item.pcThumbnailImage.url,
webtoon_link: webtoon_link,
week :mon_name,
site: site,
latest: 0
};
allWebtoonList.push(webtoon);
});
});
//화요일 다음 웹툰
var tue='tue';
var tue_name='TUE';
var daum1 = `http://webtoon.daum.net/data/pc/webtoon/list_serialized/${tue}?timeStamp=1515819276574`;
client.fetch(daum1, {}, function (err, $, res, body) {
var data = JSON.parse(body);
var list = data["data"];
list.forEach(function(item, idx){
var webtoon_link='http://webtoon.daum.net/webtoon/view/'+item.nickname.toString();
var webtoon= {
toon_index: item.id,
name : item.title,
thum_link : item.pcThumbnailImage.url,
webtoon_link : webtoon_link,
week : tue_name,
site : site,
latest : 0
};
allWebtoonList.push(webtoon);
});
});
//수요일 다음 웹툰
var wed='wed';
var wed_name='WED';
var daum2 = `http://webtoon.daum.net/data/pc/webtoon/list_serialized/${wed}?timeStamp=1515819276574`;
client.fetch(daum2, {}, function (err, $, res, body) {
var data = JSON.parse(body);
var list = data["data"];
list.forEach(function(item, idx){
var webtoon_link='http://webtoon.daum.net/webtoon/view/'+item.nickname.toString();
var webtoon= {
toon_index: item.id,
name : item.title,
thum_link : item.pcThumbnailImage.url,
webtoon_link : webtoon_link,
week : wed_name,
site : site,
latest : 0
};
allWebtoonList.push(webtoon);
});
});
//목요일 다음 웹툰
var thu='thu';
var daum3 =`http://webtoon.daum.net/data/pc/webtoon/list_serialized/${thu}?timeStamp=1515819276574`;
var thu_name='THU';
client.fetch(daum3, {}, function (err, $, res, body) {
var data = JSON.parse(body);
var list = data["data"];
list.forEach(function(item, idx){
var webtoon_link='http://webtoon.daum.net/webtoon/view/'+item.nickname.toString();
var webtoon= {
toon_index: item.id,
name : item.title,
thum_link : item.pcThumbnailImage.url,
webtoon_link : webtoon_link,
week : thu_name,
site : site,
latest : 0
};
allWebtoonList.push(webtoon);
});
});
//금요일 다음 웹툰
var fri='fri';
var daum4 =`http://webtoon.daum.net/data/pc/webtoon/list_serialized/${fri}?timeStamp=1515819276574`;
var fri_name='FRI';
client.fetch(daum4, {}, function (err, $, res, body) {
var data = JSON.parse(body);
var list = data["data"];
list.forEach(function(item, idx){
var webtoon_link='http://webtoon.daum.net/webtoon/view/'+item.nickname.toString();
var webtoon= {
toon_index: item.id,
name : item.title,
thum_link : item.pcThumbnailImage.url,
webtoon_link : webtoon_link,
week : fri_name,
site : site,
latest : 0
};
allWebtoonList.push(webtoon);
});
});
//토요일 다음 웹툰
var sat='sat';
var daum5 =`http://webtoon.daum.net/data/pc/webtoon/list_serialized/${sat}?timeStamp=1515819276574`;
var sat_name='SAT';
client.fetch(daum5, {}, function (err, $, res, body) {
var data = JSON.parse(body);
var list = data["data"];
list.forEach(function(item, idx){
var webtoon_link='http://webtoon.daum.net/webtoon/view/'+item.nickname.toString();
var webtoon= {
toon_index: item.id,
name : item.title,
thum_link : item.pcThumbnailImage.url,
webtoon_link : webtoon_link,
week : sat_name,
site : site,
latest : 0
};
allWebtoonList.push(webtoon);
});
});
//일요일 다음 웹툰
var sun='sun';
var daum6 = `http://webtoon.daum.net/data/pc/webtoon/list_serialized/${sun}?timeStamp=1515819276574`;
var sun_name='SUN';
client.fetch(daum6, {}, function (err, $, res, body) {
var data = JSON.parse(body);
var list = data["data"];
list.forEach(function(item, idx){
//다음 웹툰 아이디, 제목, 요일
var webtoon_link='http://webtoon.daum.net/webtoon/view/'+item.nickname.toString();
var webtoon= {
toon_index: item.id,
name : item.title,
thum_link : item.pcThumbnailImage.url,
webtoon_link : webtoon_link,
week : sun_name,
site : site,
latest : 0
};
allWebtoonList.push(webtoon);
});
});
//네이버 웹툰
var allWeeklyToonsUrl = "http://comic.naver.com/webtoon/weekday.nhn";
request(allWeeklyToonsUrl,function (err, res, html) {
if(!err){
var $ = cheerio.load(html);
var p = Promise.resolve();
var eachs = $(".thumb").each(function (i) {
var week = $(this).parent().parent().prev().attr('class');
var webtoon_link = "http://comic.naver.com" + $(this).children().first().attr('href');
var thumb_link = $(this).children().first().children().first().attr('src');
var name = $(this).next().text();
var titleid = webtoon_link.split('?')[1].split('&')[0].split('=')[1];
var site = 'naver';
var webtoon= {
toon_index: titleid,
name : name,
thum_link : thumb_link,
webtoon_link : webtoon_link,
week : week,
site : site,
latest : 0
};
allWebtoonList.push(webtoon);
});
p.then(function() {
i = 0;
allWebtoonList.forEach(function (webtoon) {
var sql= "INSERT INTO `toon` (toon_index, name, thum_link, webtoon_link, week, site, latest) VALUES(?) ON DUPLICATE KEY UPDATE latest=latest";
var values=[webtoon.toon_index, webtoon.name, webtoon.thum_link, webtoon.webtoon_link,webtoon.week, webtoon.site, webtoon.latest];
connection.query(sql,[values],function(err,result){
if (err) {
console.log("웹툰 DB 에러 : " + err);
} else {
// console.log("웹툰 DB처리 완료!");
}
});
//});
})
});
}
});
allWebtoons = allWebtoonList;
};
allWebtoons2 = new Array();
function getAllToons2() {
allWebtoonList2 = new Array();
//연재 완료 연도별 다음 웹툰
var daum = 'http://webtoon.daum.net/data/pc/webtoon/list_finished/?genre_id=&timeStamp=1575275921086';
var site = 'daum';
client.fetch(daum, {}, function (err, $, res, body) {
var data = JSON.parse(body);
var list = data["data"];
list.forEach(function (item, idx) {
var webtoon_link = 'http://webtoon.daum.net/webtoon/view/' + item.nickname.toString();
var yyyy = (item.finishDate).substring(0,4)
var webtoon = {
name: item.title,
thum_link: item.pcThumbnailImage.url,
webtoon_link: webtoon_link,
year : yyyy
}
allWebtoonList2.push(webtoon);
});
});
allWebtoons2 = allWebtoonList2;
}
allWebtoons3 = new Array();
function getAllToons3(){
allWebtoonList3 = new Array();
//2019년 연재 네이버 웹툰
const naver2019 = 'https://comic.naver.com/webtoon/period.nhn?period=2019';
axios.get(naver2019).then(res => {
if (res.status === 200) {
let naver2019 = [];
const $ = cheerio.load(res.data);
const $toonList = $('#content > div.list_area.daily_img > ul > li');
var tn = 2019;
$toonList.each(function (i) {
naver2019[i] = {
title: $(this).find('dl > dt > a').text(),
img: $(this).find('div > a > img').attr('src'),
index: $(this).find('li > div > a').attr('href'),
year : tn
};
});
const data = naver2019.filter(m => m.title);
allWebtoonList3.push(data);
//console.log(allWebtoonList3)
}
}, (error) => console.log(error));
//2018년 연재 네이버 웹툰
const naver2018 = 'https://comic.naver.com/webtoon/period.nhn?period=2018';
axios.get(naver2018).then(res => {
if (res.status === 200) {
let naver2018 = [];
const $ = cheerio.load(res.data);
const $toonList = $('#content > div.list_area.daily_img > ul > li');
var tn = 2018;
$toonList.each(function (i) {
naver2018[i] = {
title: $(this).find('dl > dt > a').text(),
img: $(this).find('div > a > img').attr('src'),
index: $(this).find('li > div > a').attr('href'),
year : tn
};
});
const data = naver2018.filter(m => m.title);
allWebtoonList3.push(data);
//console.log(allWebtoonList3)
}
}, (error) => console.log(error));
//2017년 연재 네이버 웹툰
const naver2017 = 'https://comic.naver.com/webtoon/period.nhn?period=2017';
axios.get(naver2017).then(res => {
if (res.status === 200) {
let naver2017 = [];
const $ = cheerio.load(res.data);
const $toonList = $('#content > div.list_area.daily_img > ul > li');
var tn = 2017;
$toonList.each(function (i) {
naver2017[i] = {
title: $(this).find('dl > dt > a').text(),
img: $(this).find('div > a > img').attr('src'),
index: $(this).find('li > div > a').attr('href'),
year : tn
};
});
const data = naver2017.filter(m => m.title);
allWebtoonList3.push(data);
//console.log(allWebtoonList3)
}
}, (error) => console.log(error));
//2016년 연재 네이버 웹툰
const naver2016 = 'https://comic.naver.com/webtoon/period.nhn?period=2016';
axios.get(naver2016).then(res => {
if (res.status === 200) {
let naver2016 = [];
const $ = cheerio.load(res.data);
const $toonList = $('#content > div.list_area.daily_img > ul > li');
var tn = 2016;
$toonList.each(function (i) {
naver2016[i] = {
title: $(this).find('dl > dt > a').text(),
img: $(this).find('div > a > img').attr('src'),
index: $(this).find('li > div > a').attr('href'),
year : tn
};
});
const data = naver2016.filter(m => m.title);
allWebtoonList3.push(data);
//console.log(allWebtoonList3)
}
}, (error) => console.log(error));
//2015년 연재 네이버 웹툰
const naver2015 = 'https://comic.naver.com/webtoon/period.nhn?period=2015';
axios.get(naver2015).then(res => {
if (res.status === 200) {
let naver2015 = [];
const $ = cheerio.load(res.data);
const $toonList = $('#content > div.list_area.daily_img > ul > li');
var tn = 2015;
$toonList.each(function (i) {
naver2015[i] = {
title: $(this).find('dl > dt > a').text(),
img: $(this).find('div > a > img').attr('src'),
index: $(this).find('li > div > a').attr('href'),
year : tn
};
});
const data = naver2015.filter(m => m.title);
allWebtoonList3.push(data);
//console.log(allWebtoonList3)
}
}, (error) => console.log(error));
//2014년 연재 네이버 웹툰
const naver2014 = 'https://comic.naver.com/webtoon/period.nhn?period=2014';
axios.get(naver2014).then(res => {
if (res.status === 200) {
let naver2014 = [];
const $ = cheerio.load(res.data);
const $toonList = $('#content > div.list_area.daily_img > ul > li');
var tn = 2014;
$toonList.each(function (i) {
naver2014[i] = {
title: $(this).find('dl > dt > a').text(),
img: $(this).find('div > a > img').attr('src'),
index: $(this).find('li > div > a').attr('href'),
year : tn
};
});
const data = naver2014.filter(m => m.title);
allWebtoonList3.push(data);
//console.log(allWebtoonList3)
}
}, (error) => console.log(error));
//2013년 연재 네이버 웹툰
const naver2013 = 'https://comic.naver.com/webtoon/period.nhn?period=2013';
axios.get(naver2013).then(res => {
if (res.status === 200) {
let naver2013 = [];
const $ = cheerio.load(res.data);
const $toonList = $('#content > div.list_area.daily_img > ul > li');
var tn = 2013;
$toonList.each(function (i) {
naver2013[i] = {
title: $(this).find('dl > dt > a').text(),
img: $(this).find('div > a > img').attr('src'),
index: $(this).find('li > div > a').attr('href'),
year : tn
};
});
const data = naver2013.filter(m => m.title);
allWebtoonList3.push(data);
//console.log(allWebtoonList3)
}
}, (error) => console.log(error));
//2012년 연재 네이버 웹툰
const naver2012 = 'https://comic.naver.com/webtoon/period.nhn?period=2012';
axios.get(naver2012).then(res => {
if (res.status === 200) {
let naver2012 = [];
const $ = cheerio.load(res.data);
const $toonList = $('#content > div.list_area.daily_img > ul > li');
var tn = 2012;
$toonList.each(function (i) {
naver2012[i] = {
title: $(this).find('dl > dt > a').text(),
img: $(this).find('div > a > img').attr('src'),
index: $(this).find('li > div > a').attr('href'),
year : tn
};
});
const data = naver2012.filter(m => m.title);
allWebtoonList3.push(data);
//console.log(allWebtoonList3)
}
}, (error) => console.log(error));
//2011년 연재 네이버 웹툰
const naver2011 = 'https://comic.naver.com/webtoon/period.nhn?period=2011';
axios.get(naver2011).then(res => {
if (res.status === 200) {
let naver2011 = [];
const $ = cheerio.load(res.data);
const $toonList = $('#content > div.list_area.daily_img > ul > li');
var tn = 2011;
$toonList.each(function (i) {
naver2011[i] = {
title: $(this).find('dl > dt > a').text(),
img: $(this).find('div > a > img').attr('src'),
index: $(this).find('li > div > a').attr('href'),
year : tn
};
});
const data = naver2011.filter(m => m.title);
allWebtoonList3.push(data);
//console.log(allWebtoonList3)
}
}, (error) => console.log(error));
//2010년 연재 네이버 웹툰
const naver2010 = 'https://comic.naver.com/webtoon/period.nhn?period=2010';
axios.get(naver2010).then(res => {
if (res.status === 200) {
let naver2010 = [];
const $ = cheerio.load(res.data);
const $toonList = $('#content > div.list_area.daily_img > ul > li');
var tn = 2010;
$toonList.each(function (i) {
naver2010[i] = {
title: $(this).find('dl > dt > a').text(),
img: $(this).find('div > a > img').attr('src'),
index: $(this).find('li > div > a').attr('href'),
year : tn
};
});
const data = naver2010.filter(m => m.title);
allWebtoonList3.push(data);
//console.log(allWebtoonList3)
}
}, (error) => console.log(error));
//2009년 연재 네이버 웹툰
const naver2009 = 'https://comic.naver.com/webtoon/period.nhn?period=2009';
axios.get(naver2009).then(res => {
if (res.status === 200) {
let naver2009 = [];
const $ = cheerio.load(res.data);
const $toonList = $('#content > div.list_area.daily_img > ul > li');
var tn = 2009;
$toonList.each(function (i) {
naver2009[i] = {
title: $(this).find('dl > dt > a').text(),
img: $(this).find('div > a > img').attr('src'),
index: $(this).find('li > div > a').attr('href'),
year : tn
};
});
const data = naver2009.filter(m => m.title);
allWebtoonList3.push(data);
//console.log(allWebtoonList3)
}
}, (error) => console.log(error));
//2008년 연재 네이버 웹툰
const naver2008 = 'https://comic.naver.com/webtoon/period.nhn?period=2008';
axios.get(naver2008).then(res => {
if (res.status === 200) {
let naver2008 = [];
const $ = cheerio.load(res.data);
const $toonList = $('#content > div.list_area.daily_img > ul > li');
var tn = 2008;
$toonList.each(function (i) {
naver2008[i] = {
title: $(this).find('dl > dt > a').text(),
img: $(this).find('div > a > img').attr('src'),
index: $(this).find('li > div > a').attr('href'),
year : tn
};
});
const data = naver2008.filter(m => m.title);
allWebtoonList3.push(data);
//console.log(allWebtoonList3)
}
}, (error) => console.log(error));
//2007년 연재 네이버 웹툰
const naver2007 = 'https://comic.naver.com/webtoon/period.nhn?period=2007';
axios.get(naver2007).then(res => {
if (res.status === 200) {
let naver2007 = [];
const $ = cheerio.load(res.data);
const $toonList = $('#content > div.list_area.daily_img > ul > li');
var tn = 2007;
$toonList.each(function (i) {
naver2007[i] = {
title: $(this).find('dl > dt > a').text(),
img: $(this).find('div > a > img').attr('src'),
index: $(this).find('li > div > a').attr('href'),
year : tn
};
});
const data = naver2007.filter(m => m.title);
allWebtoonList3.push(data);
//console.log(allWebtoonList3)
}
}, (error) => console.log(error));
//2006년 연재 네이버 웹툰
const naver2006 = 'https://comic.naver.com/webtoon/period.nhn?period=2006';
axios.get(naver2006).then(res => {
if (res.status === 200) {
let naver2006 = [];
const $ = cheerio.load(res.data);
const $toonList = $('#content > div.list_area.daily_img > ul > li');
var tn = 2006;
$toonList.each(function (i) {
naver2006[i] = {
title: $(this).find('dl > dt > a').text(),
img: $(this).find('div > a > img').attr('src'),
index: $(this).find('li > div > a').attr('href'),
year : tn
};
});
const data = naver2006.filter(m => m.title);
allWebtoonList3.push(data);
//console.log(allWebtoonList3)
}
}, (error) => console.log(error));
//2005년 연재 네이버 웹툰
const naver2005 = 'https://comic.naver.com/webtoon/period.nhn?period=2005';
axios.get(naver2005).then(res => {
if (res.status === 200) {
let naver2005 = [];
const $ = cheerio.load(res.data);
const $toonList = $('#content > div.list_area.daily_img > ul > li');
var tn = 2005;
$toonList.each(function (i) {
naver2005[i] = {
title: $(this).find('dl > dt > a').text(),
img: $(this).find('div > a > img').attr('src'),
index: $(this).find('li > div > a').attr('href'),
year : tn
};
});
const data = naver2005.filter(m => m.title);
allWebtoonList3.push(data);
//console.log(allWebtoonList3)
}
}, (error) => console.log(error));
allWebtoons3 = allWebtoonList3;
}
getAllToons();
//처음 한번 수행
setInterval(getAllToons,5*60*1000);
//5분에 한번 수행
getAllToons2();
setInterval(getAllToons2,5*60*1000);
getAllToons3();
setInterval(getAllToons3,5*60*1000);
/* GET home page. */
//진아 : list :allWebtoons2.3 해도 되는지??!!
router.get('/',
function(req,res,next){
if(req.isAuthenticated()){
res.redirect('/mytoons');
console.log("(!)이미 로그인");
}else{
console.log("(!)로그인세션 없음");
res.render('index',{
title: "니툰내툰",
list: allWebtoons
list: allWebtoons2
list: allWebtoons3
});
}
});
module.exports = router;