김진우

조회순, 별점순 고르기

......@@ -8,6 +8,7 @@ var mysql = require('mysql');
var cheerio = require('cheerio');
var request = require('request');
var index = require('./routes/index');
var index2 = require('./routes/index2');
var login = require('./routes/login');
var users = require('./routes/users');
var mytoons = require('./routes/mytoons');
......@@ -58,6 +59,8 @@ app.use(session({
app.use(passport.initialize());
app.use(passport.session());
app.use('/', index);
app.use('/ViewScore', index);
app.use('/StarScore',index2);
app.use('/login', login);
app.use('/users', users);
app.use('/mytoons', mytoons);
......
......@@ -305,7 +305,7 @@ function getAllToons() {
});
//네이버 웹툰
var allWeeklyToonsUrl = "http://comic.naver.com/webtoon/weekday.nhn?order=StarScore";
var allWeeklyToonsUrl = "https://comic.naver.com/webtoon/weekday.nhn";
request(allWeeklyToonsUrl,function (err, res, html) {
if(!err){
var $ = cheerio.load(html);
......
var express = require('express');
var cheerio = require('cheerio');
var request = require('request');
var router = express.Router();
var mysql = require('mysql');
var client = require('cheerio-httpcli');
var passport = require('passport'),
KakaoStrategy = require('passport-kakao').Strategy,
naverstrategy = require('passport-naver').Strategy,
googlestrategy = require('passport-google-oauth20').Strategy;
const puppeteer = require("puppeteer");
var connection = mysql.createConnection({
host : 'localhost',
user : 'soap',
password : '111111',
port : 3306,
database : 'ytmt'
});
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('/');
})
passport.use(new naverstrategy({
clientID : "TfrHnvzNcOTnzT6v6glC",
clientSecret : "YI1CmmOqTy",
callbackURL : "/auth/login/naver/callback"
}, function(accessToken, refreshToken, profile, done) {
// console.log("Hello world");
loginByThirdparty(accessToken, refreshToken, profile);
console.log("(!)로그인 : " + profile._json.id);
//return done(null,profile)
return done(null, {
'user_id': profile._json.id,
//'nickname': profile._json.properties.nickname
});
}))
router.get('/auth/login/naver',
passport.authenticate('naver')
)
router.get('/auth/login/naver/callback', passport.authenticate('naver', {
failureRedirect: '/',
successRedirect: '/mytoons'
})
)
passport.use(new googlestrategy( {
clientID : "214039775018-qhv7ha12dd410qfstc4n3nlhbqmblhd2.apps.googleusercontent.com",
clientSecret: "2DINnGZ--TaTG3bhZfDkAhN0",
callbackURL : "/auth/login/google/callback"
}, function (accessToken, refreshToken, profile, done) {
console.log("Hello world");
// User.findOrCreate({
// googleId: profile.id
// }, function (err, user) {
// return done(err, user);
// });
loginByThirdparty(accessToken, refreshToken, profile);
console.log("(!)로그인 : " + profile._json.id);
//return done(null,profile)
return done(null, {
'user_id': profile._json.id,
//'nickname': profile._json.properties.nickname
});
}
));
router.get('/auth/login/google',
passport.authenticate('google',{
scope: ['https://www.googleapis.com/auth/plus.login']
})
);
router.get('/auth/login/google/callback', passport.authenticate('google', {
failureRedirect: '/',
successRedirect: '/mytoons'
}));
allWebtoons2 = new Array();
function getLatestToon(titleid, day ,cb) {
}
function getAllToons() {
allWebtoonList2 = 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
};
allWebtoonList2.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
};
allWebtoonList2.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
};
allWebtoonList2.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
};
allWebtoonList2.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
};
allWebtoonList2.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
};
allWebtoonList2.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
};
allWebtoonList2.push(webtoon);
});
});
//네이버 웹툰
var allWeeklyToonsUrl = "https://comic.naver.com/webtoon/weekday.nhn?order=StarScore";
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
};
allWebtoonList2.push(webtoon);
});
p.then(function() {
i = 0;
allWebtoonList2.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처리 완료!");
}
});
//});
})
});
}
});
allWebtoons2 = allWebtoonList2;
};
popularWWebtoons = new Array();
function getPopularToons() {
var pplWebtoonList = new Array();
puppeteer.launch().then(async browser => {
let page = await browser.newPage();
await page.goto("https://comic.naver.com/index.nhn", { waitUntil: "networkidle2" });
page.waitForNavigation(), // 해당 페이지의 탐색이 완료되면 클릭 이벤트를 실행
await page.click("#recommandWebtoonRankWTabOver > a"); // 클릭이벤트를 실행
let ehList = await page.$$("div.thumb6");
for (let eh of ehList) {
let webtoon_link = await eh.$eval('a', function (el) {
return el.getAttribute('href');
});
let thumb_link = await eh.$eval('a img', function (el) {
return el.getAttribute('src');
});
let title = await eh.$eval('a', function (el) {
return el.getAttribute('title');
});
var pplObj= {
thumb_link : thumb_link,
webtoon_link : "http://comic.naver.com" + webtoon_link,
title : title
};
pplWebtoonList.push(pplObj);
}
browser.close();
popularWWebtoons = pplWebtoonList;
});
}
getAllToons();
//처음 한번 수행
setInterval(getAllToons,5*60*1000);
//5분에 한번 수행
getPopularToons();
/* GET home page. */
router.get('/',
function(req,res,next){
if(req.isAuthenticated()){
res.redirect('/mytoons');
console.log("(!)이미 로그인");
}else{
console.log("(!)로그인세션 없음");
res.render('index2',{
title: "니툰내툰",
list: allWebtoons2,
pplWList : popularWWebtoons
});
}
});
module.exports = router;
......@@ -17,20 +17,6 @@
<link href="https://fonts.googleapis.com/css?family=Dancing+Script:400,700" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Gugi&amp;subset=korean" rel="stylesheet">
<script src="http://developers.kakao.com/sdk/js/kakao.min.js">
function daum_click()
{
if(Daum_webtoons.display == "none")
Daum_webtoons.display == "block";
if(Daum_webtoons.display = "block")
Daum_webtoons.display == "none";
}
function naver_click()
{
if(Naver_webtoons.display == "none")
Naver_webtoons.display == "block";
if(Naver_webtoons.display = "block")
Naver_webtoons.display == "none";
}
</script>
</head>
<body id="page-top" data-spy="scroll" data-target=".navbar-fixed-top">
......@@ -84,7 +70,7 @@
<!--수정해주세욤!-->
<p>마더 프로젝트 니툰내툰(YTMT)를 개선하는 프로젝트입니다. 네이버 웹툰 뿐만 아니라 다음 웹툰도 담을 수 있으며, 타인이 담은 웹툰도 확인할 수 있습니다.</p>
<h3>Programmers</h3>
<p>2018102184 김진우</p>
<p>2017110276 이혜리 | 2018102184 김진우 | 2018102228 정대욱</p>
</div>
</div>
</div>
......@@ -154,8 +140,8 @@
</div>
<!--<br>-->
<font size = 30>
네이버 웹툰
<font size = 10>
&nbsp;&nbsp;네이버 웹툰
</font>
<a onclick="Naver_webtoons.style.display=(Naver_webtoons.style.display=='none') ?'block':'none';" href="javascript:void(0)">
<img src ='/images/navericon.png' width="83" height="90"/>
......@@ -187,14 +173,13 @@
</table>
</div>
<a onclick="Naver_webtoons.style.display=(Naver_webtoons.style.display=='none') ">
<button>별점순</button>
</a>
<a onclick="Naver_webtoons.style.display=(Naver_webtoons.style.display=='none') ">
<br>
<a href="/ViewScore">
<button>조회순</button>
</a>
<a href="/StarScore">
<button>별점순</button>
</a>
<table>
......@@ -205,7 +190,6 @@
if(current!=list[webtoon].week && list[webtoon].site == 'naver'){
if(current!=""){
%>
</tr>
<% } %>
<tr>
<th><%= list[webtoon].week %></th>
......@@ -218,7 +202,9 @@
<a href="<%= list[webtoon].webtoon_link %>">
<img alt="img" width="83" height="90" src="<%= list[webtoon].thum_link %>"/>
</a>
<a style="color: black">
<%= list[webtoon].name %>
</a>
</td>
<%
}
......@@ -233,8 +219,8 @@
}
}
%>
</tr>
</table>
</br>
......
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
<link rel='stylesheet' href='/stylesheets/style.css' />
<<!-- Bootstrap -->
<link rel="stylesheet" type="text/css" href="/stylesheets/bootstrap.css">
<link rel="stylesheet" type="text/css" href="/stylesheets/font-awesome.css">
<!-- Stylesheet
================================================== -->
<link rel="stylesheet" type="text/css" href="/stylesheets/style.css">
<link rel="stylesheet" type="text/css" href="/stylesheets/nivo-lightbox/nivo-lightbox.css">
<link rel="stylesheet" type="text/css" href="/stylesheets/nivo-lightbox/default.css">
<link href="https://fonts.googleapis.com/css?family=Raleway:300,400,500,600,700" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Dancing+Script:400,700" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Gugi&amp;subset=korean" rel="stylesheet">
<script src="http://developers.kakao.com/sdk/js/kakao.min.js">
</script>
</head>
<body id="page-top" data-spy="scroll" data-target=".navbar-fixed-top">
<!-- Navigation
==========================================-->
<nav id="menu" class="navbar navbar-default navbar-fixed-top">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button>
<a class="navbar-brand page-scroll" href="#page-top" style="font-family:Gugi">니툰내툰</a> </div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="#about" class="page-scroll">about</a></li>
<li><a href="#portfolio" class="page-scroll">Webtoos</a></li>
<li><a href="/login" class="page-scroll">Login</a></li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
</nav>
<!-- Header -->
<header id="header">
<div class="intro">
<div class="overlay">
<div class="container">
<div class="row">
<div class="intro-text">
<h1 style="font-family:Gugi">니툰내툰</h1>
<p>NAVER / DAUM / WEBTOONS</p>
<a href="#about" class="btn btn-custom btn-lg page-scroll">All the Webtoons</a> </div>
</div>
</div>
</div>
</div>
</header>
<!-- About Section -->
<div id="about">
<div class="container">
<div class="row">
<div class="col-xs-12 col-md-6 ">
<div class="about-img"><img src="images/toon.png" class="img-responsive" alt=""></div>
</div>
<div class="col-xs-12 col-md-6">
<div class="about-text">
<h2>Our Term-Project</h2>
<hr>
<!--수정해주세욤!-->
<p>마더 프로젝트 니툰내툰(YTMT)를 개선하는 프로젝트입니다. 네이버 웹툰 뿐만 아니라 다음 웹툰도 담을 수 있으며, 타인이 담은 웹툰도 확인할 수 있습니다.</p>
<h3>Programmers</h3>
<p>2017110276 이혜리 | 2018102184 김진우 | 2018102228 정대욱</p>
</div>
</div>
</div>
</div>
</div>
<!-- Portfolio Section -->
<div id="portfolio">
<div class="section-title text-center center">
<div class="overlay">
<h2>Gallery</h2>
<hr>
<p>니툰내툰에서 제공하는 웹툰 리스트입니다</p>
</div>
</div>
<div class="container">
<div class="row">
<div class="categories">
<ul class="cat">
<font size = 30>
다음 웹툰
</font>
<a onclick="Daum_webtoons.style.display=(Daum_webtoons.style.display=='none')?'block':'none';" href="javascript:void(0)">
<img src ='/images/daumicon.png' width="83" height="90" onclick="daum_click" />
</a>
<div style="display:none" id="Daum_webtoons">
<table>
<%
var current = "";
for(webtoon in list){
if(current!=list[webtoon].week && list[webtoon].site == 'daum'){
if(current!=""){
%>
</tr>
<% } %>
<tr>
<th><%= list[webtoon].week %></th>
<% } %>
<%
if(list[webtoon].site == 'daum')
{
%>
<td>
<a href="<%= list[webtoon].webtoon_link %>">
<img alt="img" width="83" height="90" src="<%= list[webtoon].thum_link %>"/>
</a>
<%= list[webtoon].name %>
</td>
<%
}
%>
<%
if(current!=list[webtoon].week) {
current = list[webtoon].week;
%>
<%
}
}
%>
</tr>
</table>
<!--</br>-->
</div>
<!--<br>-->
<font size = 10>
&nbsp;&nbsp;네이버 웹툰
</font>
<a onclick="Naver_webtoons.style.display=(Naver_webtoons.style.display=='none') ?'block':'none';" href="javascript:void(0)">
<img src ='/images/navericon.png' width="83" height="90"/>
</a>
<div id="Naver_webtoons" style = "display:none">
</br>
<div class="Pupular" style= "border: 1px solid; padding: 12px; width:650px; height:330px; margin:auto;">
<table>
<p>20대 실시간 인기순위</p>
<tr>
<th align = "center"> 여자</th>
</tr>
<tr>
<% let i = 1;
for(toon in pplWList) {
%>
<th><%= i%></th>
<th>
<a href="<%= pplWList[toon].webtoon_link %>">
<img alt="img" width="43" height="50" src="<%= pplWList[toon].thumb_link %>" />
</a>
<%= pplWList[toon].title %>
</th>
</tr>
<% i += 1; %>
<% } %>
</table>
</div>
<br>
<a href="/ViewScore">
<button>조회순</button>
</a>
<a href="/StarScore">
<button>별점순</button>
</a>
<table>
<%
var current = "";
for(webtoon in list){
if(current!=list[webtoon].week && list[webtoon].site == 'naver'){
if(current!=""){
%>
<% } %>
<tr>
<th><%= list[webtoon].week %></th>
<% } %>
<%
if(list[webtoon].site == 'naver')
{
%>
<td>
<a href="<%= list[webtoon].webtoon_link %>">
<img alt="img" width="83" height="90" src="<%= list[webtoon].thum_link %>"/>
</a>
<a style="color: black">
<%= list[webtoon].name %>
</a>
</td>
<%
}
%>
<%
if(current!=list[webtoon].week) {
current = list[webtoon].week;
%>
<%
}
}
%>
</tr>
</table>
</br>
</div>
</body>
</html>