/
index.js
102 lines (80 loc) · 2.33 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
const steem = require('steem');
const Timer = require('setinterval');
var Store = require("jfs");
var db = new Store("data");
var async = require("async");
var express = require('express');
var path = __dirname + '/views/';
var app = express();
app.use(express.static(__dirname + '/public'));
app.get('/', function(req, res) {
async.series(
[
function(callback) {
db.get("DynamicGlobalProperties", function(err, obj){
callback(null,obj);
});
}
], function(err, results) {
res.render(path + "index.ejs", {result: results[0]});
});
});
app.get('/download', function(req, res) {
var file = __dirname + '/data/DynamicGlobalProperties.json';
res.download(file);
});
var server = app.listen(process.env.PORT || 8080, function(err) {
if (err) throw err;
});
setInterval(function() {
async.waterfall (
[
function(callback) {
prop = {}
steem.api.getDynamicGlobalProperties(function(err, result) {
if (err) throw err;
reg = /([\d].*) [A-z].*/g
prop.time = result.time;
prop.current_sbd_supply = Number((result.current_sbd_supply).replace(reg,'$1'));
prop.virtual_supply = Number((result.virtual_supply).replace(reg,'$1'));
prop.sbd_print_rate = result.sbd_print_rate;
prop.current_supply = Number((result.current_supply).replace(reg,'$1'));
console.log(prop)
callback(null, prop);
});
},
function(prop,callback) {
steem.api.getCurrentMedianHistoryPrice(function(err, result) {
reg = /([\d].*) [A-z].*/g
quote = Number((result.quote).replace(reg,'$1'));
base = Number((result.base).replace(reg,'$1'));
prop.medianPrice = base/quote;
ratio = 100*((prop.current_sbd_supply / prop.medianPrice)/ prop.virtual_supply);
prop.ratio = ratio;
callback(null, prop);
});
},
function(prop,callback) {
db.get("DynamicGlobalProperties", function(err, obj){
if(err) {
array = [];
array.push(prop);
callback(null,array);
}
else {
obj.push(prop);
callback(null,obj);
}
})
},
function(array, callback) {
db.save("DynamicGlobalProperties", array, function(err){
if(err) throw err;
console.log("GlobalProperties saved");
});
}
])
},21600000);
process.on('uncaughtException', function (err) {
console.log('error','UNCAUGHT EXCEPTION - keeping process alive:', err.message);
});