Showing
7 changed files
with
228 additions
and
75 deletions
This diff is collapsed. Click to expand it.
... | @@ -54,16 +54,49 @@ router.get('/auth/logout/kakao',function (req,res) { | ... | @@ -54,16 +54,49 @@ router.get('/auth/logout/kakao',function (req,res) { |
54 | res.redirect('/'); | 54 | res.redirect('/'); |
55 | }) | 55 | }) |
56 | 56 | ||
57 | -var allWebtoons; | 57 | +allWebtoons = new Array(); |
58 | + | ||
59 | +function getLatestToon(titleid, day ,cb) { | ||
60 | + var url = "http://comic.naver.com/webtoon/list.nhn?titleId=" + titleid+ "&weekday="+day; | ||
61 | + console.log(url); | ||
62 | + request(url, function (err, res, html) { | ||
63 | + if (!err) { | ||
64 | + var $ = cheerio.load(html); | ||
65 | + var latestLink = 'http://comic.naver.com'; | ||
66 | + var latest; | ||
67 | + var t = $('#content > table > tbody > tr > td.title > a').first().each(function () { | ||
68 | + latestLink += $(this).attr('href'); | ||
69 | + setTimeout(function () {},100); | ||
70 | + latest = latestLink.split('?')[1].split('&')[1].split('=')[1]; | ||
71 | + }); | ||
72 | + | ||
73 | + var latestImage; | ||
74 | + $('#content > table > tbody > tr > td > a > img').first().each(function () { | ||
75 | + latestImage = $(this).attr('src'); | ||
76 | + setTimeout(function () {},100); | ||
77 | + }); | ||
78 | + | ||
79 | + cb({ | ||
80 | + latest: latest, | ||
81 | + latestLink: latestLink, | ||
82 | + latestImage: latestImage | ||
83 | + }); | ||
84 | + | ||
85 | + } else { | ||
86 | + console.log("최신화 못가져왔습니다."); | ||
87 | + //throw err; | ||
88 | + } | ||
89 | + }); | ||
90 | +} | ||
58 | 91 | ||
59 | function getAllToons() { | 92 | function getAllToons() { |
60 | var allWeeklyToonsUrl = "http://comic.naver.com/webtoon/weekday.nhn"; | 93 | var allWeeklyToonsUrl = "http://comic.naver.com/webtoon/weekday.nhn"; |
61 | - //connection.connect(); | 94 | + allWebtoonList = new Array(); |
62 | - allWebtoonJSONList = new Array(); | ||
63 | request(allWeeklyToonsUrl,function (err, res, html) { | 95 | request(allWeeklyToonsUrl,function (err, res, html) { |
64 | if(!err){ | 96 | if(!err){ |
65 | var $ = cheerio.load(html); | 97 | var $ = cheerio.load(html); |
66 | - $(".thumb").each(function (i) { | 98 | + var p = Promise.resolve(); |
99 | + var eachs = $(".thumb").each(function (i) { | ||
67 | var week = $(this).parent().parent().prev().attr('class'); | 100 | var week = $(this).parent().parent().prev().attr('class'); |
68 | var webtoon_link = "http://comic.naver.com" + $(this).children().first().attr('href'); | 101 | var webtoon_link = "http://comic.naver.com" + $(this).children().first().attr('href'); |
69 | var thumb_link = $(this).children().first().children().first().attr('src'); | 102 | var thumb_link = $(this).children().first().children().first().attr('src'); |
... | @@ -75,25 +108,37 @@ function getAllToons() { | ... | @@ -75,25 +108,37 @@ function getAllToons() { |
75 | name : name, | 108 | name : name, |
76 | thum_link : thumb_link, | 109 | thum_link : thumb_link, |
77 | webtoon_link : webtoon_link, | 110 | webtoon_link : webtoon_link, |
78 | - week : week | 111 | + week : week, |
112 | + latest : 0 | ||
79 | }; | 113 | }; |
80 | - webtoon_string = JSON.stringify(webtoon); | ||
81 | - | ||
82 | - connection.query("INSERT INTO toon SET ? ON DUPLICATE KEY UPDATE toon_index=toon_index", | ||
83 | - webtoon); | ||
84 | 114 | ||
85 | - //JSON으로 만든당. | 115 | + allWebtoonList.push(webtoon); |
86 | - allWebtoonJSONList.push(webtoon_string); | 116 | + }); |
87 | - }) | 117 | + p.then(function() { |
118 | + i = 0; | ||
119 | + allWebtoonList.forEach(function (webtoon) { | ||
120 | + getLatestToon(webtoon.toon_index, webtoon.week, function (latest_toon) { | ||
121 | + webtoon.latest = latest_toon.latest; | ||
122 | + console.log(i + " = " + webtoon.name + " : " + webtoon.latest) | ||
123 | + i++; | ||
124 | + connection.query("INSERT INTO toon SET ? ON DUPLICATE KEY UPDATE latest=?", | ||
125 | + [webtoon,webtoon.latest], function () { | ||
126 | + if(err){ | ||
127 | + console.log("웹툰 갱신중 에러!"); | ||
128 | + } | ||
129 | + }); | ||
130 | + }); | ||
131 | + }) | ||
132 | + }); | ||
88 | } | 133 | } |
89 | - //connection.end(); | ||
90 | }); | 134 | }); |
91 | - allWebtoons = allWebtoonJSONList; | 135 | + allWebtoons = allWebtoonList; |
92 | } | 136 | } |
93 | 137 | ||
94 | getAllToons(); | 138 | getAllToons(); |
95 | -setInterval(getAllToons,5000); | 139 | +//처음 한번 수행 |
96 | -//5초에 한번 수행 | 140 | +setInterval(getAllToons,5*60*1000); |
141 | +//5분에 한번 수행 | ||
97 | 142 | ||
98 | /* GET home page. */ | 143 | /* GET home page. */ |
99 | router.get('/', | 144 | router.get('/', | ... | ... |
... | @@ -7,6 +7,7 @@ var router = express.Router(); | ... | @@ -7,6 +7,7 @@ var router = express.Router(); |
7 | function getUpdatedToons(cb){ | 7 | function getUpdatedToons(cb){ |
8 | var allToons = new Array(); | 8 | var allToons = new Array(); |
9 | var allToonsUrl = "http://comic.naver.com/webtoon/weekday.nhn"; | 9 | var allToonsUrl = "http://comic.naver.com/webtoon/weekday.nhn"; |
10 | + | ||
10 | request(allToonsUrl, function(err, res, html){ | 11 | request(allToonsUrl, function(err, res, html){ |
11 | if(!err){ | 12 | if(!err){ |
12 | var $ = cheerio.load(html); | 13 | var $ = cheerio.load(html); |
... | @@ -18,7 +19,6 @@ function getUpdatedToons(cb){ | ... | @@ -18,7 +19,6 @@ function getUpdatedToons(cb){ |
18 | var toonHref = link.attr('href'); | 19 | var toonHref = link.attr('href'); |
19 | 20 | ||
20 | allToons[toonName] = toonHref; | 21 | allToons[toonName] = toonHref; |
21 | - //connection.query(""); | ||
22 | }); | 22 | }); |
23 | }); | 23 | }); |
24 | p.then(function(){ | 24 | p.then(function(){ |
... | @@ -32,8 +32,8 @@ function getUpdatedToons(cb){ | ... | @@ -32,8 +32,8 @@ function getUpdatedToons(cb){ |
32 | } | 32 | } |
33 | 33 | ||
34 | function getMyToons(id,cb){ | 34 | function getMyToons(id,cb){ |
35 | - var sqlquery = 'SELECT name, thum_link, webtoon_link, week, last FROM user u, user_toon_relation ur, toon t WHERE u.id=? && u.id=ur.user_id && t.toon_index=ur.toon_index;'; | 35 | + var sqlquery = 'SELECT name, thum_link, webtoon_link, week, last, latest FROM user u, user_toon_relation ur, toon t WHERE u.id=? && u.id=ur.user_id && t.toon_index=ur.toon_index;'; |
36 | - var mylist; | 36 | + var mylist = new Array(); |
37 | connection.query(sqlquery,id,function(err,rows,result){ | 37 | connection.query(sqlquery,id,function(err,rows,result){ |
38 | if(!err){ | 38 | if(!err){ |
39 | mylist=rows; | 39 | mylist=rows; |
... | @@ -48,32 +48,24 @@ function getMyToons(id,cb){ | ... | @@ -48,32 +48,24 @@ function getMyToons(id,cb){ |
48 | 48 | ||
49 | /* GET home page. */ | 49 | /* GET home page. */ |
50 | router.get('/', function(req, res, next) { | 50 | router.get('/', function(req, res, next) { |
51 | - async.series( | 51 | + if(!req.isAuthenticated()){ |
52 | - [ | 52 | + res.redirect('/'); |
53 | - function(callback){ | 53 | + }else{ |
54 | - getMyToons(req.user.user_id, function (mytoon_list) { | 54 | + async.series( |
55 | - callback(null,mytoon_list); | 55 | + [ |
56 | - }); | 56 | + function(callback){ |
57 | - }, | 57 | + getMyToons(req.user.user_id, function (mytoon_list) { |
58 | - function(callback){ | 58 | + callback(null,mytoon_list); |
59 | - getUpdatedToons(function (updated_list) { | 59 | + }); |
60 | - callback(null,updated_list); | 60 | + } |
61 | - }); | 61 | + ], |
62 | - } | 62 | + function(err, results){ |
63 | - ], | 63 | + res.render('mytoons', { |
64 | - function(err, results){ | 64 | + mytoons: results[0] |
65 | - console.log(results); | 65 | + }); |
66 | - res.render('mytoons', { | 66 | + } |
67 | - mytoons: results[0], | 67 | + ); |
68 | - updatedtoons: results[1] | 68 | + } |
69 | - }); | ||
70 | - } | ||
71 | - ); | ||
72 | - | ||
73 | - | ||
74 | - | ||
75 | - | ||
76 | - | ||
77 | }); | 69 | }); |
78 | 70 | ||
79 | module.exports = router; | 71 | module.exports = router; |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | var express = require('express'); | 1 | var express = require('express'); |
2 | var router = express.Router(); | 2 | var router = express.Router(); |
3 | -require('../routes/mytoons'); | ||
4 | 3 | ||
5 | 4 | ||
6 | -router.get('/', function(req, res, next) { | 5 | +function addMyToons(id,index,cb){ |
7 | - res.render('setting',{ | 6 | + connection.query("INSERT INTO user_toon_relation SET ?;", |
8 | - list : updatedToons | 7 | + {user_id : id,toon_index : index, last : 1},function (err) { |
8 | + if(err) { | ||
9 | + throw err; | ||
10 | + console.log("내 웹툰 추가중 에러!") | ||
11 | + } else{ | ||
12 | + //alert("추가되었습니다.") | ||
13 | + cb(); | ||
14 | + } | ||
15 | + }); | ||
16 | +} | ||
17 | + | ||
18 | +router.post('/toggle_toon',function(req,res,next){ | ||
19 | + var index = req.body.toon_index; | ||
20 | + var id = req.user.user_id; | ||
21 | + | ||
22 | + connection.query("SELECT COUNT(*) FROM user_toon_relation WHERE user_id=? && toon_index=?", | ||
23 | + [id,index], function (err, rows,result) { | ||
24 | + if(err){ | ||
25 | + console.log("내웹툰 등록중 에러!"); | ||
26 | + }else{ | ||
27 | + var count = rows[0]["COUNT(*)"]; | ||
28 | + if(count>0){//이미 등록되어 있는 것이라면, | ||
29 | + connection.query("DELETE FROM user_toon_relation WHERE user_id=? && toon_index=?;", | ||
30 | + [id, index],function (err, rows, result) { | ||
31 | + if(err) { | ||
32 | + console.log("내 웹툰 제거중 에러!"); | ||
33 | + throw err; | ||
34 | + }else{ | ||
35 | + //alert("제거되었습니다.") | ||
36 | + res.redirect('/setting'); | ||
37 | + } | ||
38 | + }); | ||
39 | + }else{ | ||
40 | + addMyToons(id,index,function(){ | ||
41 | + res.redirect('/setting'); | ||
42 | + }); | ||
43 | + } | ||
44 | + } | ||
45 | + }); | ||
46 | +}); | ||
47 | + | ||
48 | +function getMyToons(id,cb){ | ||
49 | + var sqlquery = 'SELECT name, thum_link, webtoon_link, week, last FROM user u, user_toon_relation ur, toon t WHERE u.id=? && u.id=ur.user_id && t.toon_index=ur.toon_index;'; | ||
50 | + var mylist = new Array(); | ||
51 | + connection.query(sqlquery,id,function(err,rows,result){ | ||
52 | + if(!err){ | ||
53 | + mylist=rows; | ||
54 | + cb(mylist); | ||
55 | + }else{ | ||
56 | + console.log("내 웹툰 리스트 가져오는데 실패했습니다!"); | ||
57 | + //throw err; | ||
58 | + } | ||
9 | }); | 59 | }); |
60 | +} | ||
61 | + | ||
62 | +router.get('/', function(req, res, next) { | ||
63 | + getMyToons(req.user.user_id,function (mytoons) { | ||
64 | + res.render('setting',{ | ||
65 | + alltoons : allWebtoons, | ||
66 | + mytoons : mytoons | ||
67 | + }); | ||
68 | + }) | ||
10 | }); | 69 | }); |
11 | 70 | ||
12 | module.exports = router; | 71 | module.exports = router; |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -14,25 +14,24 @@ | ... | @@ -14,25 +14,24 @@ |
14 | <table> | 14 | <table> |
15 | <% | 15 | <% |
16 | var current = ""; | 16 | var current = ""; |
17 | - for(jsonString in list){ | 17 | + for(webtoon in list){ |
18 | - var A=JSON.parse(list[jsonString]); | 18 | + if(current!=list[webtoon].week){ |
19 | - if(current!=A.week){ | ||
20 | if(current!=""){ | 19 | if(current!=""){ |
21 | %> | 20 | %> |
22 | </tr> | 21 | </tr> |
23 | <% } %> | 22 | <% } %> |
24 | <tr> | 23 | <tr> |
25 | - <th><%= A.week %></th> | 24 | + <th><%= list[webtoon].week %></th> |
26 | <% } %> | 25 | <% } %> |
27 | <td> | 26 | <td> |
28 | - <a href="<%= A.webtoon_link %>"> | 27 | + <a href="<%= list[webtoon].webtoon_link %>"> |
29 | - <img alt="img" width="83" height="90" src="<%= A.thum_link %>"/> | 28 | + <img alt="img" width="83" height="90" src="<%= list[webtoon].thum_link %>"/> |
30 | </a> | 29 | </a> |
31 | - <%= A.name %> | 30 | + <%= list[webtoon].name %> |
32 | </td> | 31 | </td> |
33 | <% | 32 | <% |
34 | - if(current!=A.week) { | 33 | + if(current!=list[webtoon].week) { |
35 | - current = A.week; | 34 | + current = list[webtoon].week; |
36 | %> | 35 | %> |
37 | 36 | ||
38 | <% | 37 | <% | ... | ... |
... | @@ -3,8 +3,27 @@ | ... | @@ -3,8 +3,27 @@ |
3 | <head> | 3 | <head> |
4 | <title>내툰</title> | 4 | <title>내툰</title> |
5 | <link rel='stylesheet' href='/stylesheets/style.css' /> | 5 | <link rel='stylesheet' href='/stylesheets/style.css' /> |
6 | - <script src="http://developers.kakao.com/sdk/js/kakao.min.js"></script> | 6 | + <style> |
7 | - | 7 | + .toon_latest,.toon_next,.toon_last,.toon_name,.toon_thumbnail{ |
8 | + width:10%; | ||
9 | + } | ||
10 | + | ||
11 | + td{ | ||
12 | + vertical-align: middle; | ||
13 | + border-bottom: 1px solid #bcbcbc; | ||
14 | + border-left: 1px solid #bcbcbc; | ||
15 | + border-right: 1px solid #bcbcbc; | ||
16 | + margin:0; | ||
17 | + Text-align:center; | ||
18 | + } | ||
19 | + table{ | ||
20 | + border-collapse:collapse; | ||
21 | + border: 2px solid #474747; | ||
22 | + } | ||
23 | + th{ | ||
24 | + border-bottom:2px solid #474747; | ||
25 | + } | ||
26 | + </style> | ||
8 | </head> | 27 | </head> |
9 | <h1>내툰</h1> | 28 | <h1>내툰</h1> |
10 | <p>추가한 리스트</p> | 29 | <p>추가한 리스트</p> |
... | @@ -14,15 +33,23 @@ | ... | @@ -14,15 +33,23 @@ |
14 | </br> | 33 | </br> |
15 | 34 | ||
16 | <table> | 35 | <table> |
17 | - | 36 | + <tr> |
18 | - <% | 37 | + <th>썸네일</th> |
19 | - | 38 | + <th>웹툰명</th> |
39 | + <th>최근에 본 화</th> | ||
40 | + <th>다음화</th> | ||
41 | + <th>최신화</th> | ||
42 | + </tr><% | ||
20 | for(i=0;i<mytoons.length; i++){ | 43 | for(i=0;i<mytoons.length; i++){ |
21 | - %> | 44 | + %><tr> |
22 | - <%= mytoons[i].name + " : " + mytoons[i].week %><br> | 45 | + <td class="toon_thumbnail"><image src="<%= mytoons[i].thum_link%>"/></td> |
23 | - <% | 46 | + <td class="toon_name"><%= mytoons[i].name %></td> |
24 | - } | 47 | + <td class="toon_last"><%= mytoons[i].last %>화</td> |
25 | - %> | 48 | + <td class="toon_next"><%= mytoons[i].last +1 %>화</td> |
49 | + <td class="toon_latest"><%= mytoons[i].latest %>화</td> | ||
50 | + </tr> | ||
51 | + <br> | ||
52 | + <% } %> | ||
26 | </table> | 53 | </table> |
27 | 54 | ||
28 | </br> | 55 | </br> | ... | ... |
... | @@ -3,23 +3,54 @@ | ... | @@ -3,23 +3,54 @@ |
3 | <head> | 3 | <head> |
4 | <meta charset="UTF-8"> | 4 | <meta charset="UTF-8"> |
5 | <title>설정</title> | 5 | <title>설정</title> |
6 | + <style> | ||
7 | + .registered{ | ||
8 | + background-color: #AAAAAA; | ||
9 | + } | ||
10 | + </style> | ||
6 | </head> | 11 | </head> |
7 | <h1>내툰</h1> | 12 | <h1>내툰</h1> |
8 | -<p>추가하거나 제거할 웹툰을 눌러주세요.</p> | 13 | +<p>추가하거나 제거할 웹툰을 선택해주세요.</p> |
9 | 14 | ||
10 | <table> | 15 | <table> |
11 | - | ||
12 | <% | 16 | <% |
13 | var current = ""; | 17 | var current = ""; |
14 | - for(toonName in mytoons) { | 18 | + for(webtoon in alltoons){ |
15 | - var A = mytoons[toonName]; | 19 | + if(current!=alltoons[webtoon].week){ |
20 | + if(current!=""){ | ||
21 | + %> | ||
22 | + </tr> | ||
23 | + <% } %> | ||
24 | + <tr> | ||
25 | + <th><%= alltoons[webtoon].week %></th> | ||
26 | + <% } %> | ||
27 | + <td class="<% | ||
28 | + for(i=0;i<mytoons.length;i++){ | ||
29 | + if(mytoons[i].name == alltoons[webtoon].name){ | ||
30 | + %>registered<% | ||
31 | + break; | ||
32 | + } | ||
33 | + } | ||
34 | + %>"> | ||
35 | + <form method="post" action="/setting/toggle_toon"> | ||
36 | + <input type="hidden" name="toon_index" value="<%= alltoons[webtoon].toon_index %>"> | ||
37 | + <input TYPE="IMAGE" src="<%= alltoons[webtoon].thum_link %>" name="Submit" value="Submit" align="absmiddle"> | ||
38 | + </form> | ||
39 | + <%= alltoons[webtoon].name; %> | ||
40 | + </td> | ||
41 | + <% | ||
42 | + if(current!=alltoons[webtoon].week) { | ||
43 | + current = alltoons[webtoon].week; | ||
16 | %> | 44 | %> |
17 | - <%= A %></br> | 45 | + |
18 | - <% | 46 | + <% |
19 | - } | 47 | + } |
48 | + } | ||
20 | %> | 49 | %> |
50 | + </tr> | ||
21 | 51 | ||
22 | </table> | 52 | </table> |
53 | +</form> | ||
23 | </br> | 54 | </br> |
24 | 55 | ||
25 | <body> | 56 | <body> | ... | ... |
-
Please register or login to post a comment