diff options
Diffstat (limited to 'nodes/currency_thread.lua')
-rw-r--r-- | nodes/currency_thread.lua | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/nodes/currency_thread.lua b/nodes/currency_thread.lua new file mode 100644 index 0000000..77b98dc --- /dev/null +++ b/nodes/currency_thread.lua @@ -0,0 +1,22 @@ +local socket = require("socket") +local http = require("socket.http") +local json = require("vendor.json") +local lume = require("vendor.lume") + +local btcURL = 'http://www.bitmarket.pl/json/BTCPLN/ticker.json' +local tryURL = 'http://api.fixer.io/latest?base=TRY' + +local r, c, h = http.request(btcURL) +if c == 200 then + btcpln = json.decode(r)['last'] + local r, c, h = http.request(tryURL) + if c == 200 then + tryidr = json.decode(r)['rates']['IDR'] + end + love.thread.getChannel('currency'):push({ + values = {math.floor(btcpln), math.floor(tryidr)}, + }) + print("Update finished") +else + print("Update failed") +end |