Showing
2 changed files
with
22 additions
and
6 deletions
| ... | @@ -4,18 +4,29 @@ const app = express(); | ... | @@ -4,18 +4,29 @@ const app = express(); |
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | const fetch = require('node-fetch'); | 6 | const fetch = require('node-fetch'); |
| 7 | -const fs = require('fs') | 7 | +const fs = require('fs'); |
| 8 | - | ||
| 9 | 8 | ||
| 10 | const api_key = fs.readFileSync('apikey', 'ascii') | 9 | const api_key = fs.readFileSync('apikey', 'ascii') |
| 11 | console.log('apikey:',api_key) | 10 | console.log('apikey:',api_key) |
| 12 | //const url = 'https://api.whale-alert.io/v1/status?api_key=' + api_key | 11 | //const url = 'https://api.whale-alert.io/v1/status?api_key=' + api_key |
| 13 | const options = {method: 'GET', headers: {Accept: 'application/json'}}; | 12 | const options = {method: 'GET', headers: {Accept: 'application/json'}}; |
| 14 | 13 | ||
| 15 | -cursor = '' | 14 | +var cursor = '' |
| 16 | -const url2 = 'https://api.whale-alert.io/v1/transactions?api_key=' + api_key; | 15 | +url2 = 'https://api.whale-alert.io/v1/transactions?api_key=' + api_key + '&limit=1&cursor=' + cursor; |
| 17 | 16 | ||
| 17 | +//Initialize timestamp | ||
| 18 | 18 | ||
| 19 | +const fs2 = require('fs') | ||
| 20 | +const fs3 = require('fs') | ||
| 21 | +var TimeNow = parseInt((new Date()).getTime() / 1000) | ||
| 22 | +console.log(TimeNow) | ||
| 23 | +console.log('파일쓰기') | ||
| 24 | +fetch(url2, options) | ||
| 25 | +.then(res => res.json()) | ||
| 26 | +.then(json => { | ||
| 27 | + console.log(json) | ||
| 28 | + fs2.writeFileSync('timestamp', json.cursor, 'ascii') | ||
| 29 | +}) | ||
| 19 | // fetch(url, options) | 30 | // fetch(url, options) |
| 20 | // .then(res => res.json()) | 31 | // .then(res => res.json()) |
| 21 | // .then(json => console.log(json)) | 32 | // .then(json => console.log(json)) |
| ... | @@ -32,7 +43,7 @@ function data_collector(data, limit){ | ... | @@ -32,7 +43,7 @@ function data_collector(data, limit){ |
| 32 | var ret = ''; | 43 | var ret = ''; |
| 33 | var str = ''; | 44 | var str = ''; |
| 34 | 45 | ||
| 35 | - for(var i = 0; i < data.transactions.length; i++){ | 46 | + for(var i = 0; i < data.count; i++){ |
| 36 | str = '#' + (i+1)+' ChainName: '+data.transactions[i].blockchain+'\tAmount: '+data.transactions[i].amount+' USD' | 47 | str = '#' + (i+1)+' ChainName: '+data.transactions[i].blockchain+'\tAmount: '+data.transactions[i].amount+' USD' |
| 37 | if(data.transactions[i].amount > limit){ | 48 | if(data.transactions[i].amount > limit){ |
| 38 | //console.log(str) | 49 | //console.log(str) |
| ... | @@ -45,15 +56,19 @@ function data_collector(data, limit){ | ... | @@ -45,15 +56,19 @@ function data_collector(data, limit){ |
| 45 | return ret; | 56 | return ret; |
| 46 | } | 57 | } |
| 47 | app.get('/', function (req, res) { | 58 | app.get('/', function (req, res) { |
| 48 | - fu = fetch(url2, options); | 59 | + cursor = fs3.readFileSync('timestamp', 'ascii') |
| 60 | + console.log('cursor', url2) | ||
| 61 | + fu = fetch(url2+cursor, options); | ||
| 49 | fu.then(res => res.json()) | 62 | fu.then(res => res.json()) |
| 50 | .then(json => { | 63 | .then(json => { |
| 51 | //API usage limit | 64 | //API usage limit |
| 52 | console.log(json) | 65 | console.log(json) |
| 66 | + | ||
| 53 | if(json.result == 'error'){ | 67 | if(json.result == 'error'){ |
| 54 | res.send("Please try later") | 68 | res.send("Please try later") |
| 55 | } | 69 | } |
| 56 | else{ | 70 | else{ |
| 71 | + fs2.writeFileSync('timestamp', json.cursor, 'ascii') | ||
| 57 | res.send(chk_param(json, req.query.limit, data_collector)) | 72 | res.send(chk_param(json, req.query.limit, data_collector)) |
| 58 | } | 73 | } |
| 59 | }) | 74 | }) | ... | ... |
-
Please register or login to post a comment