hyunjong

index.js were been clean codes

......@@ -30,7 +30,7 @@ passport.use(new KakaoStrategy({
}
));
// kakao 로그인, // passport.authenticate('kakao',{state: "myStateValue"})
// kakao 로그인
router.get('/auth/login/kakao', passport.authenticate('kakao'));
// kakao 로그인 연동 콜백
......@@ -68,6 +68,85 @@ function getLatestToon(titleid, day ,cb) {
}
function getDaumToons(_day){
// X요일 다음 웹툰
var day = _day;
var day_name = day;
var daum = `http://webtoon.daum.net/data/pc/webtoon/list_serialized/${day}?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 : day_name,
site : site,
latest : 0
};
allWebtoonList.push(webtoon);
});
});
}
function getNaverToons(){
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처리 완료!");
}
});
})
});
}
});
}
// 구현중
function getTomicsToons(){
}
// 설명
allWebtoons = new Array();
......@@ -77,229 +156,31 @@ 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);
});
});
getDaumToons('mon');
//화요일 다음 웹툰
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);
});
});
getDaumToons('tue');
//수요일 다음 웹툰
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);
});
});
getDaumToons('wed');
//목요일 다음 웹툰
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);
});
});
getDaumToons('thu');
//금요일 다음 웹툰
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);
});
});
getDaumToons('fri');
//토요일 다음 웹툰
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);
});
});
getDaumToons('sat');
//일요일 다음 웹툰
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);
});
});
getDaumToons('sun');
//네이버 웹툰
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처리 완료!");
}
});
})
});
}
});
getNaverToons();
//투믹스 웹툰
getTomicsToons();
allWebtoons = allWebtoonList;
};
......@@ -308,7 +189,7 @@ function getAllToons() {
getAllToons();
//5분에 한번 수행
setInterval(getAllToons,5*60*1000);
setInterval(getAllToons, 5*60*1000);
/* GET home page. */
router.get('/', function(req,res,next) {
......