All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
4 Licensed under GNU General Public License v2
9 local newtimer = require("lain.helpers").newtimer
10 local json = require("lain.util").dkjson
12 local wibox = require("wibox")
14 local string = { format = string.format }
15 local tonumber = tonumber
17 -- Crypto currencies widget
18 -- lain.widgets.contrib.ccurr
24 -- using Coinbase and Cryptsy APIs.
26 -- requires http://dkolf.de/src/dkjson-lua.fsl/home
27 -- based upon http://awesome.naquadah.org/wiki/Bitcoin_Price_Widget
29 local function get(url)
30 local f = io.popen('curl -m 5 -s "' .. url .. '"')
34 local s = f:read("*all")
40 local function parse(j)
41 local obj, pos, err = json.decode(j, 1, nil)
49 local function worker(args)
50 local args = args or {}
51 local timeout = args.timeout or 600
52 local btc_url = args.btc_url or "https://coinbase.com/api/v1/prices/buy"
53 local doge_url = args.doge_url or "http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=132"
54 local settings = args.settings or function() end
56 ccurr.widget = wibox.widget.textbox('')
58 local function update()
64 btc = parse(get(btc_url))
65 doge = parse(get(doge_url))
68 price_now.btc = tonumber(btc["subtotal"]["amount"])
69 price_now.doge = tonumber(doge["return"]["markets"]["DOGE"]["lasttradeprice"])
70 price_now.doge = string.format("%.4f", price_now.btc * price_now.doge)
77 newtimer("ccurr", timeout, update)
82 return setmetatable(ccurr, { __call = function(_, ...) return worker(...) end })