Serge Bazanski | 18c1a26 | 2022-07-07 14:24:53 +0200 | [diff] [blame] | 1 | local socket = require("socket") |
| 2 | local http = require("socket.http") |
| 3 | local json = require("vendor.json") |
| 4 | local lume = require("vendor.lume") |
| 5 | |
| 6 | local btcURL = 'http://www.bitmarket.pl/json/BTCPLN/ticker.json' |
| 7 | local tryURL = 'http://api.fixer.io/latest?base=TRY' |
| 8 | |
| 9 | local r, c, h = http.request(btcURL) |
| 10 | if c == 200 then |
| 11 | btcpln = json.decode(r)['last'] |
| 12 | local r, c, h = http.request(tryURL) |
| 13 | if c == 200 then |
| 14 | tryidr = json.decode(r)['rates']['IDR'] |
| 15 | end |
| 16 | love.thread.getChannel('currency'):push({ |
| 17 | values = {math.floor(btcpln), math.floor(tryidr)}, |
| 18 | }) |
| 19 | print("Update finished") |
| 20 | else |
| 21 | print("Update failed") |
| 22 | end |