index4.js
5.69 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
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('/');
})
//--------------------------------------------------------------------------------------------------------
allWebtoons4 = new Array();
function getAllToons4() {
allWebtoonList4 = new Array();
//현재 상영작 좋아요 순
const currentlikemovie = 'https://movie.naver.com/movie/running/current.nhn?view=list&tab=normal&order=likeCount';
axios.get(currentlikemovie).then(res => {
if (res.status === 200) {
let currentLikeMovie = [];
const $ = cheerio.load(res.data);
const $movieList = $('div.lst_wrap ul.lst_detail_t1').children('li');
$movieList.each(function (i) {
currentLikeMovie[i] = {
title: $(this).find('dt.tit a').text(),
img: $(this).find('div.thumb img').attr('src')
//개봉예정작에선 star가 없음
//star: $(this).find('em.num_likeit').text().replace(/\t/gi, '').replace(/\n/gi,'')
};
});
const data = currentLikeMovie.filter(m => m.title);
allWebtoonList4.push(data);
//console.log(data);
}
}, (error) => console.log(error));
//현재 상영작 예매 순
const runningreserve = 'https://movie.naver.com/movie/running/current.nhn?view=list&tab=normal&order=reserve';
axios.get(runningreserve).then(res => {
if (res.status === 200) {
let crawledMovie = [];
const $ = cheerio.load(res.data);
const $movieList = $('div.lst_wrap ul.lst_detail_t1').children('li');
$movieList.each(function (i) {
crawledMovie[i] = {
title: $(this).find('dt.tit a').text(),
img: $(this).find('div.thumb img').attr('src')
};
});
const data = crawledMovie.filter(m => m.title);
allWebtoonList4.push(data);
//console.log(data);
}
}, (error) => console.log(error));
//개봉 예정영화 기대지수순
const premovieinterest = 'https://movie.naver.com/movie/running/premovie.nhn?order=interestRate';
axios.get(premovieinterest).then(res => {
if (res.status === 200) {
let crawledMovie = [];
const $ = cheerio.load(res.data);
const $movieList = $('div.lst_wrap ul.lst_detail_t1').children('li');
$movieList.each(function (i) {
crawledMovie[i] = {
title: $(this).find('dt.tit a').text(),
img: $(this).find('div.thumb img').attr('src')
};
});
const data = crawledMovie.filter(m => m.title);
allWebtoonList4.push(data);
//console.log(data);
}
}, (error) => console.log(error));
//계봉 예정영화 예매순
const prereserve = 'https://movie.naver.com/movie/running/premovie.nhn?order=reserve';
axios.get(prereserve).then(res => {
if (res.status === 200) {
let crawledMovie = [];
const $ = cheerio.load(res.data);
const $movieList = $('div.lst_wrap ul.lst_detail_t1').children('li');
$movieList.each(function (i) {
crawledMovie[i] = {
title: $(this).find('dt.tit a').text(),
img: $(this).find('div.thumb img').attr('src')
};
});
const data = crawledMovie.filter(m => m.title);
allWebtoonList4.push(data);
//console.log(data);
}
}, (error) => console.log(error));
allWebtoons4 = allWebtoonList4;
}
getAllToons4();
setInterval(getAllToons4,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: allWebtoons4
});
}
});
module.exports = router;