배지승

거래 시간대 UTC에서 한국 시간대로 변경

...@@ -2,8 +2,8 @@ const request = require('request'); ...@@ -2,8 +2,8 @@ const request = require('request');
2 const TARGET_URL = 'https://api.line.me/v2/bot/message/push' 2 const TARGET_URL = 'https://api.line.me/v2/bot/message/push'
3 const MULTI_TARGET_URL = 'https://api.line.me/v2/bot/message/multicast' 3 const MULTI_TARGET_URL = 'https://api.line.me/v2/bot/message/multicast'
4 const BROAD_TARGET_URL = 'https://api.line.me/v2/bot/message/broadcast' 4 const BROAD_TARGET_URL = 'https://api.line.me/v2/bot/message/broadcast'
5 -const TOKEN = ''//Token, userid 입력후 사용 5 +const TOKEN = 'ePTcnuOEn0TvohbtMRnbZRo0YqKVUOyjkkZ/jE6qh5VC5dajFgFBuWY+MAzdY8VKybwB34iz2AbFRtM0G9fL0+Xo4U+Lz7uBNpCo5m//COlWZdQsx1Ywmh61NopAomnNjWT41rNV1YyvI9aeX5CKxgdB04t89/1O/w1cDnyilFU='
6 -const USER_ID = '' 6 +const USER_ID = 'U2988a9f8583a616c1285db2224662211'
7 7
8 const express = require('express'); 8 const express = require('express');
9 const app = express(); 9 const app = express();
...@@ -14,19 +14,41 @@ var cursor = '' ...@@ -14,19 +14,41 @@ var cursor = ''
14 url2 = 'https://api.whale-alert.io/v1/transactions?api_key=' + api_key + '&cursor=' + cursor; 14 url2 = 'https://api.whale-alert.io/v1/transactions?api_key=' + api_key + '&cursor=' + cursor;
15 const options = {method: 'GET', headers: {Accept: 'application/json'}}; 15 const options = {method: 'GET', headers: {Accept: 'application/json'}};
16 16
17 +const KR_TIME_DIFF = 9 * 60 * 60 * 1000;
17 var TimeNow = parseInt((new Date()).getTime() / 1000) 18 var TimeNow = parseInt((new Date()).getTime() / 1000)
18 var uts2time = new Date() 19 var uts2time = new Date()
19 20
20 console.log(TimeNow) 21 console.log(TimeNow)
21 -fetch(url2, options) //커서값(갱신)을 얻기 위한 fetch 22 +
23 +fetch(url2, options)
22 .then(res => res.json()) 24 .then(res => res.json())
23 .then(json => { 25 .then(json => {
24 - console.log(json) 26 + console.log(json)
25 - cursor = json.cursor 27 + fetch(url2+json.cursor, options)
26 -}) 28 + .then(res => res.json())
29 + .then(json => {
30 + console.log(json)
31 + fetch(url2+json.cursor, options)
32 + .then(res => res.json())
33 + .then(json => {
34 + console.log(json)
35 + if(json.cursor != undefined){
36 + cursor = json.cursor
37 + }
38 + })
39 + .catch((err) => {
40 + console.log('error : inital_fetch:'+err)
41 + })
42 + })
43 + .catch((err) => {
44 + console.log('error : inital_fetch:'+err)
45 + })
46 + })
27 .catch((err) => { 47 .catch((err) => {
28 console.log('error : inital_fetch:'+err) 48 console.log('error : inital_fetch:'+err)
29 }) 49 })
50 +
51 +
30 function chk_param(data, query_limit, callback){ 52 function chk_param(data, query_limit, callback){
31 //query_limit (non_int) => return 0; 53 //query_limit (non_int) => return 0;
32 //query_limit (int) => return query_limit; 54 //query_limit (int) => return query_limit;
...@@ -40,12 +62,12 @@ function data_collector(data, limit){ ...@@ -40,12 +62,12 @@ function data_collector(data, limit){
40 62
41 //ret += '# of Transactions : ' + data.count + '\n' 63 //ret += '# of Transactions : ' + data.count + '\n'
42 for(var i = 0; i < data.count; i++){ 64 for(var i = 0; i < data.count; i++){
43 - uts2time.setTime(data.transactions[i].timestamp * 1000) 65 + uts2time.setTime(data.transactions[i].timestamp * 1000 + KR_TIME_DIFF)
44 str = /*'#' + (i+1)+*/'Time: ' + uts2time.toLocaleString() + '\nChainName: '+data.transactions[i].blockchain+'\nAmount: '+data.transactions[i].amount+' USD' 66 str = /*'#' + (i+1)+*/'Time: ' + uts2time.toLocaleString() + '\nChainName: '+data.transactions[i].blockchain+'\nAmount: '+data.transactions[i].amount+' USD'
45 - if(data.transactions[i].amount > limit){ 67 + if(data.transactions[i].amount > limit){
46 //console.log(str) 68 //console.log(str)
47 // ret += '\n\n' + str; 69 // ret += '\n\n' + str;
48 - o ={ 'type' : 'text',//message 형태에 맞춰 저장 70 + o ={ 'type' : 'text',
49 'text' : str} 71 'text' : str}
50 ret.push(o) 72 ret.push(o)
51 } 73 }
...@@ -55,7 +77,6 @@ function data_collector(data, limit){ ...@@ -55,7 +77,6 @@ function data_collector(data, limit){
55 } 77 }
56 return ret; 78 return ret;
57 } 79 }
58 -//5초 간격으로 fetch후 메시지 전송
59 setInterval(() => { 80 setInterval(() => {
60 fetch(url2+cursor, options) 81 fetch(url2+cursor, options)
61 .then(res => res.json()) 82 .then(res => res.json())
...@@ -65,8 +86,8 @@ setInterval(() => { ...@@ -65,8 +86,8 @@ setInterval(() => {
65 if(json.result == 'error'){ 86 if(json.result == 'error'){
66 } 87 }
67 else{ 88 else{
68 - cursor = json.cursor 89 + cursor = json.cursor
69 - var msg2user = chk_param(json, 0, data_collector) //fetch후 message Object 배열 리턴 90 + var msg2user = chk_param(json, 1000000, data_collector)
70 console.log('msg',msg2user) 91 console.log('msg',msg2user)
71 if(msg2user.length){ 92 if(msg2user.length){
72 var i = 0; 93 var i = 0;
...@@ -79,7 +100,7 @@ setInterval(() => { ...@@ -79,7 +100,7 @@ setInterval(() => {
79 }, 100 },
80 json: { 101 json: {
81 "to": `${USER_ID}`, 102 "to": `${USER_ID}`,
82 - "messages":[msg2user[i]] //5개 초과하면 err나서 하나씩 넣음 103 + "messages":[msg2user[i]]
83 } 104 }
84 },(error, response, body) => { 105 },(error, response, body) => {
85 console.log(body, error) 106 console.log(body, error)
......