summaryrefslogtreecommitdiffstats
path: root/nodes/currency_thread.lua
blob: 77b98dca4d28fb4f5a6f27e496c61ca5e936bc08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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