diff options
| author | Adam Soltys <[email protected]> | 2014-08-30 12:13:43 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2014-08-30 12:13:43 -0700 |
| commit | 8fe5b97004189845ee98a02ab197ca080ff0a002 (patch) | |
| tree | 1b56bad23c70ddbcf3eb965a1051eb5c03147eb5 /app.js | |
| parent | eb4c625949f7b20cbbd59dde3fd2af1d53f4449e (diff) | |
| download | coinos-server-8fe5b97004189845ee98a02ab197ca080ff0a002.tar.gz coinos-server-8fe5b97004189845ee98a02ab197ca080ff0a002.zip | |
Reimplement fetch rates function
Diffstat (limited to 'app.js')
| -rw-r--r-- | app.js | 28 |
1 files changed, 12 insertions, 16 deletions
@@ -88,24 +88,20 @@ return next(); }; - fetchRates = function() { - var file; - file = 'public/js/rates.json'; - fs.truncate(file, 0, function() { - var r, stream; - stream = fs.createWriteStream(file); - r = request("https://api.bitcoinaverage.com/exchanges/all"); - r.on('data', function(chunk) { - return stream.write(chunk); - }); - return r.on('error', function(error) { - return console.log(error); - }); + (fetchRates = function() { + request("https://api.bitcoinaverage.com/exchanges/all", function(error, response, body) { + var file, stream; + try { + require('util').isDate(JSON.parse(body).timestamp); + file = 'public/js/rates.json'; + stream = fs.createWriteStream(file); + return fs.truncate(file, 0, function() { + return stream.write(body); + }); + } catch (_error) {} }); return setTimeout(fetchRates, 120000); - }; - - fetchRates(); + })(); app.get('/', cache, sessions["new"]); |
