윤혜원

DB에 user, toon 정보 INSERT 성공!

......@@ -2,5 +2,6 @@
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$/YTMT" vcs="Git" />
</component>
</project>
\ No newline at end of file
......
This diff is collapsed. Click to expand it.
......@@ -15,9 +15,7 @@ var setting = require('./routes/setting');
var session = require('express-session');
var toonviewer = require('./routes/toonviewer');
//port
passport.serializeUser(function(user, done) {
console.log('serialized');
done(null, user);
......@@ -44,7 +42,7 @@ app.use(express.static(path.join(__dirname, 'public')));
connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'hs970010!',
password : 'password',
port : 3306,
database : 'ytmt'
});
......@@ -62,8 +60,6 @@ app.use('/users', users);
app.use('/mytoons', mytoons);
app.use('/setting', setting);
app.use('/toonviewer', toonviewer);
//app.use('/daum', daum);
//app.use(express.static('views'));
// catch 404 and forward to error handler
......
......@@ -9,8 +9,8 @@ var passport = require('passport'),
passport.use(new KakaoStrategy({
clientID : 'bd2e610396fb7bbb84cf91a786b3cc72',
callbackURL :'/auth/login/kakao/callback'
// clientSecret : 'eUtJGtlLoCZJufevp3LKfDP0KOtZUV7R'
callbackURL :'/auth/login/kakao/callback',
clientSecret : 'eUtJGtlLoCZJufevp3LKfDP0KOtZUV7R'
},
function(accessToken, refreshToken,params, profile, done){
//사용자 정보는 profile에
......@@ -41,8 +41,11 @@ router.get('/auth/login/kakao/callback',
);
function loginByThirdparty(accessToken, refreshToken, profile) {
var stmt_duplicated = 'INSERT INTO user(id) VALUES(?) ON DUPLICATE KEY UPDATE id=?;'
connection.query(stmt_duplicated, [profile._json.id] , function (err, result) {
//예전 코드는 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 {
......@@ -59,7 +62,7 @@ router.get('/auth/logout/kakao',function (req,res) {
allWebtoons = new Array();
function getLatestToon(titleid, day ,cb) {
var url = "http://comic.naver.com/webtoon/list.nhn?titleId=" + titleid+ "&weekday="+day;
/*var url = "http://comic.naver.com/webtoon/list.nhn?titleId=" + titleid+ "&weekday="+day;
console.log(url);
request(url, function (err, res, html) {
if (!err) {
......@@ -88,7 +91,7 @@ function getLatestToon(titleid, day ,cb) {
console.log("최신화 못가져왔습니다.");
//throw err;
}
});
});*/
}
function getAllToons() {
......@@ -150,7 +153,7 @@ function getAllToons() {
var list = data["data"];
list.forEach(function(item, idx){
console.log(item.id + ' ' + item.title + ' ' + wed);
var webtoon_link='http://webtoon.daum.net/webtoon/view/'+item.nickname.toString();
var webtoon= {
toon_index: item.id,
......@@ -279,23 +282,30 @@ function getAllToons() {
site : site,
latest : 0
};
allWebtoonList.push(webtoon);
});
p.then(function() {
i = 0;
allWebtoonList.forEach(function (webtoon) {
getLatestToon(webtoon.toon_index, webtoon.week, function (latest_toon) {
webtoon.latest = latest_toon.latest;
console.log(i + " = " + webtoon.name + " : " + webtoon.latest)
i++;
connection.query("INSERT INTO toon SET ? ON DUPLICATE KEY UPDATE latest=?",
[webtoon,webtoon.latest], function () {
if(err){
console.log("웹툰 갱신중 에러!");
}
// getLatestToon(webtoon.toon_index, webtoon.week, function (latest_toon) {
// webtoon.latest = latest_toon.latest;
//i++;
//console.log(i + " = " + webtoon.name + " : " + webtoon.latest);
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처리 완료!");
}
//[webtoon,webtoon.latest], function () {
// if (err) {
// console.log("웹툰 갱신중 에러!");
//}
// }
});
});
//});
})
});
}
......
......@@ -33,7 +33,11 @@ function getUpdatedToons(cb){
}
function getMyToons(id,cb){
var sqlquery = 'SELECT name, thum_link, webtoon_link, week, last, latest, t.toon_index AS toon_index FROM user u, user_toon_relation ur, toon t WHERE u.id=? && u.id=ur.user_id && t.toon_index=ur.toon_index;';
//var sql = "INSERT INTO `user` (id) VALUES (?)";
//var kid=[profile._json.id];
//connection.query(sql,kid,function(err,result){
var sqlquery = "SELECT name, thum_link, webtoon_link, week, last, t.toon_index AS toon_index FROM user u, user_toon_relation ur, toon t WHERE u.id=? && u.id=ur.user_id && t.toon_index=ur.toon_index;";
//var sqlquery = "SELECT name, thum_link, webtoon_link, week, last, latest, t.toon_index AS toon_index FROM user u, user_toon_relation ur, toon t WHERE u.id=? && u.id=ur.user_id && t.toon_index=ur.toon_index;";
var mylist = new Array();
connection.query(sqlquery,id,function(err,rows,result){
if(!err){
......