윤혜원

다음 웹툰allToons 배열에 삽입 성공!

This diff is collapsed. Click to expand it.
...@@ -13,7 +13,8 @@ var mytoons = require('./routes/mytoons'); ...@@ -13,7 +13,8 @@ var mytoons = require('./routes/mytoons');
13 var passport = require('passport'); 13 var passport = require('passport');
14 var setting = require('./routes/setting'); 14 var setting = require('./routes/setting');
15 var session = require('express-session'); 15 var session = require('express-session');
16 -var toonviewer = require('./routes/toonviewer') 16 +var toonviewer = require('./routes/toonviewer');
17 +
17 18
18 //port 19 //port
19 20
...@@ -61,6 +62,7 @@ app.use('/users', users); ...@@ -61,6 +62,7 @@ app.use('/users', users);
61 app.use('/mytoons', mytoons); 62 app.use('/mytoons', mytoons);
62 app.use('/setting', setting); 63 app.use('/setting', setting);
63 app.use('/toonviewer', toonviewer); 64 app.use('/toonviewer', toonviewer);
65 +//app.use('/daum', daum);
64 66
65 //app.use(express.static('views')); 67 //app.use(express.static('views'));
66 68
......
1 -var client = require('cheerio-httpcli');
2 -//월요일 웹툰
3 -var mon='mon'
4 -var daum = `http://webtoon.daum.net/data/pc/webtoon/list_serialized/${mon}?timeStamp=1515819276574`;
5 -
6 -client.fetch(daum, {}, function (err, $, res, body) {
7 - var data = JSON.parse(body);
8 - var list = data["data"];
9 -
10 - list.forEach(function(item, idx){
11 - //다음 웹툰 아이디, 제목, 요일
12 - console.log(item.id + ' ' + item.title + ' ' + mon);
13 - });
14 -
15 -});
16 -
17 -//화요일 웹툰
18 -var tue='tue'
19 -var daum = `http://webtoon.daum.net/data/pc/webtoon/list_serialized/${tue}?timeStamp=1515819276574`;
20 -
21 -client.fetch(daum, {}, function (err, $, res, body) {
22 - var data = JSON.parse(body);
23 - var list = data["data"];
24 -
25 - list.forEach(function(item, idx){
26 - //다음 웹툰 아이디, 제목, 요일
27 - console.log(item.id + ' ' + item.title + ' ' + tue);
28 - });
29 -
30 -});
31 -
32 -//수요일 웹툰
33 -var wed='wed'
34 -var daum = `http://webtoon.daum.net/data/pc/webtoon/list_serialized/${wed}?timeStamp=1515819276574`;
35 -
36 -client.fetch(daum, {}, function (err, $, res, body) {
37 - var data = JSON.parse(body);
38 - var list = data["data"];
39 -
40 - list.forEach(function(item, idx){
41 - //다음 웹툰 아이디, 제목, 요일
42 - console.log(item.id + ' ' + item.title + ' ' + wed);
43 - });
44 -
45 -});
46 -
47 -//목요일 웹툰
48 -var thu='thu'
49 -var daum = `http://webtoon.daum.net/data/pc/webtoon/list_serialized/${thu}?timeStamp=1515819276574`;
50 -client.fetch(daum, {}, function (err, $, res, body) {
51 - var data = JSON.parse(body);
52 - var list = data["data"];
53 -
54 - list.forEach(function(item, idx){
55 - //다음 웹툰 아이디, 제목, 요일
56 - console.log(item.id + ' ' + item.title + ' ' + thu);
57 - });
58 -
59 -});
60 -
61 -//금요일웹툰
62 -var fri='fri';
63 -var daum1 = `http://webtoon.daum.net/data/pc/webtoon/list_serialized/${fri}?timeStamp=1515819276574`;
64 -client.fetch(daum1, {}, function (err, $, res, body) {
65 - var data = JSON.parse(body);
66 - var list1 = data["data"];
67 -
68 - list1.forEach(function(item, idx){
69 - //다음 웹툰 아이디, 제목, 요일
70 - console.log(item.id + ' ' + item.title + ' ' + fri);
71 - });
72 -
73 -});
74 -
75 -//토요일 웹툰
76 -var sat='sat'
77 -var daum = `http://webtoon.daum.net/data/pc/webtoon/list_serialized/${sat}?timeStamp=1515819276574`;
78 -
79 -client.fetch(daum, {}, function (err, $, res, body) {
80 - var data = JSON.parse(body);
81 - var list = data["data"];
82 -
83 - list.forEach(function(item, idx){
84 - //다음 웹툰 아이디, 제목, 요일
85 - console.log(item.id + ' ' + item.title + ' ' + sat);
86 - });
87 -
88 -});
89 -
90 -//일요일 웹툰
91 -var sun='sun'
92 -var daum = `http://webtoon.daum.net/data/pc/webtoon/list_serialized/${sun}?timeStamp=1515819276574`;
93 -
94 -client.fetch(daum, {}, function (err, $, res, body) {
95 - var data = JSON.parse(body);
96 - var list = data["data"];
97 -
98 - list.forEach(function(item, idx){
99 - //다음 웹툰 아이디, 제목, 요일
100 - console.log(item.id + ' ' + item.title + ' ' + sun);
101 - });
102 -
103 -});
...\ No newline at end of file ...\ No newline at end of file
...@@ -3,6 +3,7 @@ var cheerio = require('cheerio'); ...@@ -3,6 +3,7 @@ var cheerio = require('cheerio');
3 var request = require('request'); 3 var request = require('request');
4 var router = express.Router(); 4 var router = express.Router();
5 var mysql = require('mysql'); 5 var mysql = require('mysql');
6 +var client = require('cheerio-httpcli');
6 var passport = require('passport'), 7 var passport = require('passport'),
7 KakaoStrategy = require('passport-kakao').Strategy; 8 KakaoStrategy = require('passport-kakao').Strategy;
8 9
...@@ -41,8 +42,7 @@ router.get('/auth/login/kakao/callback', ...@@ -41,8 +42,7 @@ router.get('/auth/login/kakao/callback',
41 42
42 function loginByThirdparty(accessToken, refreshToken, profile) { 43 function loginByThirdparty(accessToken, refreshToken, profile) {
43 var stmt_duplicated = 'INSERT INTO user(id) VALUES(?) ON DUPLICATE KEY UPDATE id=?;' 44 var stmt_duplicated = 'INSERT INTO user(id) VALUES(?) ON DUPLICATE KEY UPDATE id=?;'
44 - 45 + connection.query(stmt_duplicated, [profile._json.id] , function (err, result) {
45 - connection.query(stmt_duplicated, [profile._json.id,profile._json.id] , function (err, result) {
46 if (err) { 46 if (err) {
47 console.log("로그인 쿼리중 에러 : " + err); 47 console.log("로그인 쿼리중 에러 : " + err);
48 } else { 48 } else {
...@@ -92,8 +92,180 @@ function getLatestToon(titleid, day ,cb) { ...@@ -92,8 +92,180 @@ function getLatestToon(titleid, day ,cb) {
92 } 92 }
93 93
94 function getAllToons() { 94 function getAllToons() {
95 - var allWeeklyToonsUrl = "http://comic.naver.com/webtoon/weekday.nhn";
96 allWebtoonList = new Array(); 95 allWebtoonList = new Array();
96 +//월요일 다음 웹툰
97 + var mon='mon';
98 + var daum = `http://webtoon.daum.net/data/pc/webtoon/list_serialized/${mon}?timeStamp=1515819276574`;
99 + var site='daum';
100 + var mon_name='MON';
101 + client.fetch(daum, {}, function (err, $, res, body) {
102 + var data = JSON.parse(body);
103 + var list = data["data"];
104 + console.log(list);
105 + list.forEach(function(item, idx){
106 + var webtoon_link='http://webtoon.daum.net/webtoon/view/'+item.nickname.toString();
107 + var webtoon= {
108 + toon_index: item.id,
109 + name : item.title,
110 + thum_link : webtoon_link,
111 + webtoon_link : webtoon_link,
112 + week : mon_name,
113 + site : site,
114 + latest : 0
115 + };
116 + allWebtoonList.push(webtoon);
117 + });
118 + });
119 +//화요일 다음 웹툰
120 + var tue='tue';
121 + var tue_name='TUE';
122 + var daum1 = `http://webtoon.daum.net/data/pc/webtoon/list_serialized/${tue}?timeStamp=1515819276574`;
123 +
124 + client.fetch(daum1, {}, function (err, $, res, body) {
125 + var data = JSON.parse(body);
126 + var list = data["data"];
127 +
128 + list.forEach(function(item, idx){
129 + var webtoon_link='http://webtoon.daum.net/webtoon/view/'+item.nickname.toString();
130 + var webtoon= {
131 + toon_index: item.id,
132 + name : item.title,
133 + thum_link : webtoon_link,
134 + webtoon_link : webtoon_link,
135 + week : tue_name,
136 + site : site,
137 + latest : 0
138 + };
139 +
140 + allWebtoonList.push(webtoon);
141 + });
142 +
143 + });
144 +
145 +//수요일 다음 웹툰
146 + var wed='wed';
147 + var wed_name='WED';
148 + var daum2 = `http://webtoon.daum.net/data/pc/webtoon/list_serialized/${wed}?timeStamp=1515819276574`;
149 +
150 + client.fetch(daum2, {}, function (err, $, res, body) {
151 + var data = JSON.parse(body);
152 + var list = data["data"];
153 +
154 + list.forEach(function(item, idx){
155 + console.log(item.id + ' ' + item.title + ' ' + wed);
156 + var webtoon_link='http://webtoon.daum.net/webtoon/view/'+item.nickname.toString();
157 + var webtoon= {
158 + toon_index: item.id,
159 + name : item.title,
160 + thum_link : webtoon_link,
161 + webtoon_link : webtoon_link,
162 + week : wed_name,
163 + site : site,
164 + latest : 0
165 + };
166 + allWebtoonList.push(webtoon);
167 + });
168 +
169 + });
170 +
171 +//목요일 다음 웹툰
172 + var thu='thu';
173 + var daum3 = `http://webtoon.daum.net/data/pc/webtoon/list_serialized/${thu}?timeStamp=1515819276574`;
174 + var thu_name='THU';
175 + client.fetch(daum3, {}, function (err, $, res, body) {
176 + var data = JSON.parse(body);
177 + var list = data["data"];
178 + list.forEach(function(item, idx){
179 + var webtoon_link='http://webtoon.daum.net/webtoon/view/'+item.nickname.toString();
180 + var webtoon= {
181 + toon_index: item.id,
182 + name : item.title,
183 + thum_link : webtoon_link,
184 + webtoon_link : webtoon_link,
185 + week : thu_name,
186 + site : site,
187 + latest : 0
188 + };
189 + allWebtoonList.push(webtoon);
190 + });
191 +
192 + });
193 +
194 +//금요일 다음 웹툰
195 + var fri='fri';
196 + var daum4 = `http://webtoon.daum.net/data/pc/webtoon/list_serialized/${fri}?timeStamp=1515819276574`;
197 + var fri_name='FRI';
198 + client.fetch(daum4, {}, function (err, $, res, body) {
199 + var data = JSON.parse(body);
200 + var list1 = data["data"];
201 +
202 + list1.forEach(function(item, idx){
203 + var webtoon_link='http://webtoon.daum.net/webtoon/view/'+item.nickname.toString();
204 + var webtoon= {
205 + toon_index: item.id,
206 + name : item.title,
207 + thum_link : webtoon_link,
208 + webtoon_link : webtoon_link,
209 + week : fri_name,
210 + site : site,
211 + latest : 0
212 + };
213 + allWebtoonList.push(webtoon);
214 + });
215 +
216 + });
217 +
218 +//토요일 다음 웹툰
219 + var sat='sat';
220 + var daum5 = `http://webtoon.daum.net/data/pc/webtoon/list_serialized/${sat}?timeStamp=1515819276574`;
221 + var sat_name='SAT';
222 + client.fetch(daum5, {}, function (err, $, res, body) {
223 + var data = JSON.parse(body);
224 + var list = data["data"];
225 +
226 + list.forEach(function(item, idx){
227 + //다음 웹툰 아이디, 제목, 요일
228 + var webtoon_link='http://webtoon.daum.net/webtoon/view/'+item.nickname.toString();
229 + var webtoon= {
230 + toon_index: item.id,
231 + name : item.title,
232 + thum_link : webtoon_link,
233 + webtoon_link : webtoon_link,
234 + week : sat_name,
235 + site : site,
236 + latest : 0
237 + };
238 + allWebtoonList.push(webtoon);
239 + });
240 +
241 + });
242 +
243 +//일요일 다음 웹툰
244 + var sun='sun';
245 + var daum6 = `http://webtoon.daum.net/data/pc/webtoon/list_serialized/${sun}?timeStamp=1515819276574`;
246 + var sun_name='SUN'
247 + client.fetch(daum6, {}, function (err, $, res, body) {
248 + var data = JSON.parse(body);
249 + var list = data["data"];
250 +
251 + list.forEach(function(item, idx){
252 + //다음 웹툰 아이디, 제목, 요일
253 + var webtoon_link='http://webtoon.daum.net/webtoon/view/'+item.nickname.toString();
254 + var webtoon= {
255 + toon_index: item.id,
256 + name : item.title,
257 + thum_link : webtoon_link,
258 + webtoon_link : webtoon_link,
259 + week : sun_name,
260 + site : site,
261 + latest : 0
262 + };
263 + allWebtoonList.push(webtoon);
264 + });
265 +
266 + });
267 +
268 + var allWeeklyToonsUrl = "http://comic.naver.com/webtoon/weekday.nhn";
97 request(allWeeklyToonsUrl,function (err, res, html) { 269 request(allWeeklyToonsUrl,function (err, res, html) {
98 if(!err){ 270 if(!err){
99 var $ = cheerio.load(html); 271 var $ = cheerio.load(html);
...@@ -104,13 +276,14 @@ function getAllToons() { ...@@ -104,13 +276,14 @@ function getAllToons() {
104 var thumb_link = $(this).children().first().children().first().attr('src'); 276 var thumb_link = $(this).children().first().children().first().attr('src');
105 var name = $(this).next().text(); 277 var name = $(this).next().text();
106 var titleid = webtoon_link.split('?')[1].split('&')[0].split('=')[1]; 278 var titleid = webtoon_link.split('?')[1].split('&')[0].split('=')[1];
107 - 279 + var site = 'naver'
108 var webtoon= { 280 var webtoon= {
109 toon_index: titleid, 281 toon_index: titleid,
110 name : name, 282 name : name,
111 thum_link : thumb_link, 283 thum_link : thumb_link,
112 webtoon_link : webtoon_link, 284 webtoon_link : webtoon_link,
113 week : week, 285 week : week,
286 + site : site,
114 latest : 0 287 latest : 0
115 }; 288 };
116 289
...@@ -135,7 +308,7 @@ function getAllToons() { ...@@ -135,7 +308,7 @@ function getAllToons() {
135 } 308 }
136 }); 309 });
137 allWebtoons = allWebtoonList; 310 allWebtoons = allWebtoonList;
138 -} 311 +};
139 312
140 getAllToons(); 313 getAllToons();
141 //처음 한번 수행 314 //처음 한번 수행
......
...@@ -8,13 +8,13 @@ ...@@ -8,13 +8,13 @@
8 <h1><%= title %></h1> 8 <h1><%= title %></h1>
9 <p>웹툰 리스트</p> 9 <p>웹툰 리스트</p>
10 10
11 -
12 <a href="/auth/login/kakao" class="btn btn-block btn-lg btn-warning btn_login">로그인</a> 11 <a href="/auth/login/kakao" class="btn btn-block btn-lg btn-warning btn_login">로그인</a>
13 12
14 <table> 13 <table>
15 <% 14 <%
16 var current = ""; 15 var current = "";
17 for(webtoon in list){ 16 for(webtoon in list){
17 +
18 if(current!=list[webtoon].week){ 18 if(current!=list[webtoon].week){
19 if(current!=""){ 19 if(current!=""){
20 %> 20 %>
......