김대선

정보 가져오는 기능 묶음, 불필요한 라우터 제거

1 const express = require('express') 1 const express = require('express')
2 - 2 +const functions = require('./function')
3 -const naverRouter = require('./router/naver')
4 -const kakaoRouter = require('./router/kakao')
5 -const programmersRouter = require('./router/programmers')
6 3
7 const app = express(); 4 const app = express();
8 5
...@@ -12,10 +9,43 @@ const server = app.listen(3000,()=>{ ...@@ -12,10 +9,43 @@ const server = app.listen(3000,()=>{
12 console.log("app listening at http://%s:%s", host, port) 9 console.log("app listening at http://%s:%s", host, port)
13 }) 10 })
14 11
15 -app.use('/naver', naverRouter)
16 -app.use('/kakao', kakaoRouter)
17 -app.use('/programmers', programmersRouter)
18 12
19 -app.get('/', (req, res)=>{ 13 +app.get('/', async (req, res)=>{
20 - res.send("this is home!") 14 + let string = ""
15 + let data = await functions.getKakaoData()
16 + let temp = ""
17 + for(let i of data){
18 + temp = "title : " + i.title
19 + string = string + temp + "\n"
20 + temp = "tags : " + i.tags.toString()
21 + string = string + temp + "\n"
22 + temp = "url : " + i.url
23 + string = string + temp + "\n"
24 + }
25 +
26 + data = await functions.getNaverFunction()
27 + temp = ""
28 + for(let i of data){
29 + temp = "title : " + i.title
30 + string = string + temp + "\n"
31 + if(!!i.tags){
32 + temp = "tags : " + i.tags.toString()
33 + string = string + temp + "\n"
34 + }
35 + temp = "url : " + i.url
36 + string = string + temp + "\n"
37 + }
38 +
39 + data = await functions.getProgrammersFunction()
40 + temp = ""
41 + for(let i of data){
42 + temp = "title : " + i.title
43 + string = string + temp + "\n"
44 + temp = "tags : " + i.tags.toString()
45 + string = string + temp + "\n"
46 + temp = "url : " + i.url
47 + string = string + temp + "\n"
48 + }
49 +
50 + res.send(string)
21 }) 51 })
...\ No newline at end of file ...\ No newline at end of file
......
1 +const kakaoFunction = require("./functions/kakaoFunction");
2 +const naverFunction = require("./functions/naverFunction");
3 +const programmersFunction = require("./functions/programmersFunction")
4 +
5 +
6 +module.exports = {
7 + getKakaoData : kakaoFunction.getData,
8 + getNaverFunction : naverFunction.getData,
9 + getProgrammersFunction : programmersFunction.getData
10 +}
...@@ -19,7 +19,6 @@ const makeObject = (array)=>{ ...@@ -19,7 +19,6 @@ const makeObject = (array)=>{
19 tempData = splitData(i) 19 tempData = splitData(i)
20 result.push({ 20 result.push({
21 title : tempData[0], 21 title : tempData[0],
22 - term : tempData[2],
23 tags : [], 22 tags : [],
24 url : tempData[tempData.length - 1] 23 url : tempData[tempData.length - 1]
25 }) 24 })
...@@ -34,9 +33,9 @@ const makeObject = (array)=>{ ...@@ -34,9 +33,9 @@ const makeObject = (array)=>{
34 33
35 const moveNextPage = async (page)=>{ 34 const moveNextPage = async (page)=>{
36 35
37 - await page.click('#mArticle > div > div.paging_list > span > a:nth-child(11) > span > span').catch((error)=>{ 36 + await page.click('#mArticle > div > div.paging_list > span > a:nth-child(10) > span > span').catch((error)=>{
38 }) 37 })
39 - await page.waitForTimeout(300) 38 + await page.waitForTimeout(1000)
40 return await page.content() 39 return await page.content()
41 } 40 }
42 41
......
...@@ -20,7 +20,6 @@ const makeObject = (array)=>{ ...@@ -20,7 +20,6 @@ const makeObject = (array)=>{
20 if(tempData.length == 5){ 20 if(tempData.length == 5){
21 result.push({ 21 result.push({
22 title : tempData[0], 22 title : tempData[0],
23 - term : tempData[2],
24 tags : tempData[3].split('#').filter((ele)=>ele != ''), 23 tags : tempData[3].split('#').filter((ele)=>ele != ''),
25 url : tempData[4] 24 url : tempData[4]
26 }) 25 })
...@@ -28,7 +27,6 @@ const makeObject = (array)=>{ ...@@ -28,7 +27,6 @@ const makeObject = (array)=>{
28 else if (tempData.length == 4){ 27 else if (tempData.length == 4){
29 result.push({ 28 result.push({
30 title : tempData[0], 29 title : tempData[0],
31 - term : tempData[2],
32 url : tempData[3] 30 url : tempData[3]
33 }) 31 })
34 } 32 }
......
...@@ -19,7 +19,6 @@ const makeObject = (array)=>{ ...@@ -19,7 +19,6 @@ const makeObject = (array)=>{
19 tempData = splitData(i) 19 tempData = splitData(i)
20 result.push({ 20 result.push({
21 title : tempData[0], 21 title : tempData[0],
22 - term : tempData[2],
23 tags : [], 22 tags : [],
24 url : tempData[tempData.length - 1] 23 url : tempData[tempData.length - 1]
25 }) 24 })
...@@ -77,8 +76,7 @@ const getData = async ()=>{ ...@@ -77,8 +76,7 @@ const getData = async ()=>{
77 return result 76 return result
78 } 77 }
79 78
80 -getData()
81 79
82 module.exports = { 80 module.exports = {
83 - 81 + getData : getData
84 } 82 }
...\ No newline at end of file ...\ No newline at end of file
......
1 -const express = require('express')
2 -const router = express.Router()
3 -
4 -const kakaoFunction = require('./kakaoFunction')
5 -
6 -router.get('/', (req, res, error)=>{
7 - res.send('hello this is kakao')
8 -})
9 -
10 -router.get('/recruitment', async (req, res, error)=>{
11 - res.send(await kakaoFunction.getData())
12 -})
13 -
14 -module.exports = router
...\ No newline at end of file ...\ No newline at end of file
1 -const express = require('express')
2 -const router = express.Router()
3 -
4 -const naverFunction = require('./naverFunctions')
5 -
6 -router.get('/', (req, res, error)=>{
7 - res.send("naver home")
8 -})
9 -
10 -router.get('/recruitment', async (req, res, error)=>{
11 - res.send(await naverFunction.getData())
12 -})
13 -
14 -
15 -module.exports = router
...\ No newline at end of file ...\ No newline at end of file
1 -const express = require('express')
2 -const router = express.Router()
3 -
4 -const programmersFunction = require('./programmersFunction')
5 -
6 -router.get('/', (req, res, error)=>{
7 - res.send("programmers home")
8 -})
9 -
10 -router.get('/recruitment', async (req, res, error)=>{
11 - res.send("this is programmers recruitment")
12 -})
13 -
14 -
15 -module.exports = router
...\ No newline at end of file ...\ No newline at end of file