SW0000J

Merge branch 'develop' of ssh://khuhub.khu.ac.kr:12959/2019102228/2020_OSS_TermProJect into develop

1 +var express = require('express');
2 +var router = express.Router();
3 +
4 +const Xports = require('../test1.js');
5 +const Zum = require('../test2.js');
6 +const Chosun = require('../test3.js');
7 +const zum = Zum.zum;
8 +const chosun = Chosun.chosun;
9 +
10 +exports().then(a => {
11 + console.log(a);
12 +});
13 +
14 +const xports = new Array();
15 +
16 +router.get('/', function(req, res, next){
17 +
18 + res.render('index', {
19 + xports : xports,
20 + zum : zum,
21 + chosun : chosun,
22 + // yna : yna
23 + });
24 +});
25 +
26 +console.log("aaaa\n");
27 +for(var i in xports){
28 + console.log("aaaa\n");
29 + console.log(i.datetime);
30 +}
31 +module.exports = router;
1 var express = require('express'); 1 var express = require('express');
2 var router = express.Router(); 2 var router = express.Router();
3 3
4 -const Xports = require('../test1.js'); 4 +const getXports = require('../test1.js');
5 const Zum = require('../test2.js'); 5 const Zum = require('../test2.js');
6 const Chosun = require('../test3.js'); 6 const Chosun = require('../test3.js');
7 -const Yna = require('../test4.js');
8 -const xports = Xports.xports;
9 const zum = Zum.zum; 7 const zum = Zum.zum;
10 const chosun = Chosun.chosun; 8 const chosun = Chosun.chosun;
11 -const yna = Yna.yna; 9 +
10 +let xports;
11 +(async function() {
12 +try {
13 + xports = await getXports();
14 + console.log(xports);
15 +} catch (e) {
16 + return console.log(e);
17 +}
18 +})();
12 19
13 router.get('/', function(req, res, next){ 20 router.get('/', function(req, res, next){
14 21
...@@ -16,11 +23,13 @@ router.get('/', function(req, res, next){ ...@@ -16,11 +23,13 @@ router.get('/', function(req, res, next){
16 xports : xports, 23 xports : xports,
17 zum : zum, 24 zum : zum,
18 chosun : chosun, 25 chosun : chosun,
19 - yna : yna 26 + // yna : yna
20 }); 27 });
21 }); 28 });
22 29
30 +console.log("aaaa\n");
23 for(var i in xports){ 31 for(var i in xports){
32 + console.log("aaaa\n");
24 console.log(i.datetime); 33 console.log(i.datetime);
25 } 34 }
26 -module.exports = router;
...\ No newline at end of file ...\ No newline at end of file
35 +module.exports = router;
......
...@@ -13,25 +13,35 @@ const getHtml = async () => { ...@@ -13,25 +13,35 @@ const getHtml = async () => {
13 } 13 }
14 }; 14 };
15 15
16 -getHtml()
17 - .then(html => {
18 - let ulList = [];
19 - //console.log(html.data);
20 - const $ = cheerio.load(html.data);
21 - const $bodyList = $("ul.list_news > li");//.children("");
22 -
23 - $bodyList.each(function(i, elem) {
24 - ulList[i] = {
25 - url: 'xportsnews.com' + $(this).find('div.thumb > a').attr('href'),
26 - image_url: $(this).find('div.thumb > a > img').attr('src'),
27 - title: $(this).find('dl.dlist > dt > a').text(),
28 - summary: $(this).find('dd').text().slice(1, -2),
29 - datetime: $(this).find('dd > span.data').text()
30 - };
31 - //console.log(ulList[i]) // list object checking code
32 - });
33 -
34 - const data = ulList.filter(n => n.title);
35 - return data;
36 - //return ulList;
37 - }).then(res => console.log(res));
...\ No newline at end of file ...\ No newline at end of file
16 +
17 +const getXports = async () => {
18 +
19 + return new Promise((resolve, reject) => {
20 + getHtml()
21 + .then(html => {
22 + let ulList = [];
23 + //console.log(html.data);
24 + const $ = cheerio.load(html.data);
25 + const $bodyList = $("ul.list_news > li");//.children("");
26 +
27 + $bodyList.each(function(i, elem) {
28 + ulList[i] = {
29 + url: 'xportsnews.com' + $(this).find('div.thumb > a').attr('href'),
30 + image_url: $(this).find('div.thumb > a > img').attr('src'),
31 + title: $(this).find('dl.dlist > dt > a').text(),
32 + summary: $(this).find('dd').text().slice(1, -2),
33 + datetime: $(this).find('dd > span.data').text()
34 + };
35 + //console.log(ulList[i]) // list object checking code
36 + });
37 +
38 + const data = ulList.filter(n => n.title);
39 + return data;
40 + //return ulList;
41 + }).then(data => {
42 + resolve(data);
43 + });
44 +});
45 +};
46 +
47 +module.exports = getXports;
......
...@@ -31,4 +31,4 @@ getHtml() ...@@ -31,4 +31,4 @@ getHtml()
31 const data = ulList.filter(n => n.title); 31 const data = ulList.filter(n => n.title);
32 return data; 32 return data;
33 //return ulList; 33 //return ulList;
34 - }).then(res => console.log(res));
...\ No newline at end of file ...\ No newline at end of file
34 + });
......
...@@ -31,4 +31,4 @@ getHtml() ...@@ -31,4 +31,4 @@ getHtml()
31 const data = ulList.filter(n => n.title); 31 const data = ulList.filter(n => n.title);
32 return data; 32 return data;
33 //return ulList; 33 //return ulList;
34 - }).then(res => console.log(res));
...\ No newline at end of file ...\ No newline at end of file
34 + });
......
...@@ -69,4 +69,4 @@ app.use('/', indexRouter); ...@@ -69,4 +69,4 @@ app.use('/', indexRouter);
69 app.listen(PORT, function(){ 69 app.listen(PORT, function(){
70 console.log('Code run in https://localhost:'+PORT); 70 console.log('Code run in https://localhost:'+PORT);
71 }); 71 });
72 -*/
...\ No newline at end of file ...\ No newline at end of file
72 +*/
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
10 <div class = 'main'> 10 <div class = 'main'>
11 <div class = 'center'> 11 <div class = 'center'>
12 <div> 12 <div>
13 - <% for(var i in xports) { %> 13 + <% for(var i of xports) { %>
14 <li> 14 <li>
15 <div class='item'> 15 <div class='item'>
16 <div class='info'> 16 <div class='info'>
...@@ -36,4 +36,4 @@ ...@@ -36,4 +36,4 @@
36 </div> 36 </div>
37 </div> 37 </div>
38 </body> 38 </body>
39 -</html>
...\ No newline at end of file ...\ No newline at end of file
39 +</html>
......