Showing
1 changed file
with
63 additions
and
6 deletions
... | @@ -8,10 +8,11 @@ const USER_ID = '사용자의 ID, 메세지 수신 시에 확인할 수 있음' | ... | @@ -8,10 +8,11 @@ const USER_ID = '사용자의 ID, 메세지 수신 시에 확인할 수 있음' |
8 | var client_id = 'naver client_id'; | 8 | var client_id = 'naver client_id'; |
9 | var client_secret = 'naver client_secret'; | 9 | var client_secret = 'naver client_secret'; |
10 | 10 | ||
11 | -var headline = ''; | 11 | +var headline_max = ''; |
12 | +var headline_min = ''; | ||
12 | 13 | ||
13 | // Broadcast -> 채널 전체 유저에게 | 14 | // Broadcast -> 채널 전체 유저에게 |
14 | -const PushFunc = function() { | 15 | +const PushFunc_max = function() { |
15 | var api_url = 'https://openapi.naver.com/v1/search/news?query=' + encodeURI('상한가 주식'); // json 결과 | 16 | var api_url = 'https://openapi.naver.com/v1/search/news?query=' + encodeURI('상한가 주식'); // json 결과 |
16 | var options = { | 17 | var options = { |
17 | url: api_url, | 18 | url: api_url, |
... | @@ -21,9 +22,9 @@ const PushFunc = function() { | ... | @@ -21,9 +22,9 @@ const PushFunc = function() { |
21 | const obj = JSON.parse(body); | 22 | const obj = JSON.parse(body); |
22 | const str = JSON.stringify(obj.items[0]); | 23 | const str = JSON.stringify(obj.items[0]); |
23 | const obj2 = JSON.parse(str); | 24 | const obj2 = JSON.parse(str); |
24 | - if(headline == '' || headline != JSON.stringify(obj2.title).replace(/<[^>]*>?/g, '')) { | 25 | + if(headline_max == '' || headline_max != JSON.stringify(obj2.title).replace(/<[^>]*>?/g, '')) { |
25 | if (!error && response.statusCode == 200) { | 26 | if (!error && response.statusCode == 200) { |
26 | - headline = JSON.stringify(obj2.title).replace(/<[^>]*>?/g, '') | 27 | + headline_max = JSON.stringify(obj2.title).replace(/<[^>]*>?/g, '') |
27 | request.post( | 28 | request.post( |
28 | { | 29 | { |
29 | url: BROAD_TARGET_URL, | 30 | url: BROAD_TARGET_URL, |
... | @@ -59,7 +60,62 @@ const PushFunc = function() { | ... | @@ -59,7 +60,62 @@ const PushFunc = function() { |
59 | console.log('error = ' + response.statusCode); | 60 | console.log('error = ' + response.statusCode); |
60 | } | 61 | } |
61 | } else { | 62 | } else { |
62 | - console.log('새로운 소식 없음') | 63 | + console.log('새로운 소식 없음_max') |
64 | + } | ||
65 | + | ||
66 | + }); | ||
67 | + | ||
68 | + | ||
69 | + }; | ||
70 | +const PushFunc_min = function() { | ||
71 | + var api_url = 'https://openapi.naver.com/v1/search/news?query=' + encodeURI('하한가 주식'); // json 결과 | ||
72 | + var options = { | ||
73 | + url: api_url, | ||
74 | + headers: {'X-Naver-Client-Id':client_id, 'X-Naver-Client-Secret': client_secret} | ||
75 | + }; | ||
76 | + request.get(options, function (error, response, body) { | ||
77 | + const obj = JSON.parse(body); | ||
78 | + const str = JSON.stringify(obj.items[0]); | ||
79 | + const obj2 = JSON.parse(str); | ||
80 | + if(headline_min == '' || headline_min != JSON.stringify(obj2.title).replace(/<[^>]*>?/g, '')) { | ||
81 | + if (!error && response.statusCode == 200) { | ||
82 | + headline_min = JSON.stringify(obj2.title).replace(/<[^>]*>?/g, '') | ||
83 | + request.post( | ||
84 | + { | ||
85 | + url: BROAD_TARGET_URL, | ||
86 | + headers: { | ||
87 | + 'Authorization': `Bearer ${TOKEN}` | ||
88 | + }, | ||
89 | + json: { | ||
90 | + "messages": [ | ||
91 | + { | ||
92 | + "type" :"text", | ||
93 | + "text": "[하한가 소식]" | ||
94 | + }, | ||
95 | + { | ||
96 | + "type":"text", | ||
97 | + "text": "<<<헤드라인>>>\n" + JSON.stringify(obj2.title).replace(/<[^>]*>?/g, '') | ||
98 | + }, | ||
99 | + { | ||
100 | + "type":"text", | ||
101 | + "text": "<<<주요문단>>>\n" + JSON.stringify(obj2.description).replace(/<[^>]*>?/g, '') | ||
102 | + }, | ||
103 | + { | ||
104 | + "type":"text", | ||
105 | + "text": "뉴스 바로가기\n" + JSON.stringify(obj2.link) | ||
106 | + } | ||
107 | + ] | ||
108 | + } | ||
109 | + },(error, response, body) => { | ||
110 | + console.log(body) | ||
111 | + } | ||
112 | + ) | ||
113 | + } else { | ||
114 | + res.status(response.statusCode).end(); | ||
115 | + console.log('error = ' + response.statusCode); | ||
116 | + } | ||
117 | + } else { | ||
118 | + console.log('새로운 소식 없음_min') | ||
63 | } | 119 | } |
64 | 120 | ||
65 | }); | 121 | }); |
... | @@ -68,4 +124,5 @@ const PushFunc = function() { | ... | @@ -68,4 +124,5 @@ const PushFunc = function() { |
68 | }; | 124 | }; |
69 | 125 | ||
70 | 126 | ||
71 | -const intervalId = setInterval(PushFunc, 60000); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
127 | +const intervalId_max = setInterval(PushFunc_max, 60000); | ||
128 | +const intervalId_min = setInterval(PushFunc_min, 60000); | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment