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 wibox = require("wibox")
11 local json = require("dkjson")
13 -- Crypto currencies widget
14 -- lain.widgets.contrib.ccurr
20 -- using Coinbase and Cryptsy APIs.
22 -- requires http://dkolf.de/src/dkjson-lua.fsl/home
23 -- based upon http://awesome.naquadah.org/wiki/Bitcoin_Price_Widget
25 local function get(url)
26 local f = io.popen('curl -m 5 -s "' .. url .. '"')
30 local s = f:read("*all")
36 local function parse(j)
37 local obj, pos, err = json.decode(j, 1, nil)
45 local function worker(args)
46 local args = args or {}
47 local timeout = args.timeout or 600
48 local btc_url = args.btc_url or "https://coinbase.com/api/v1/prices/buy"
49 local doge_url = args.doge_url or "http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=132"
50 local settings = args.settings or function() end
52 ccurr.widget = wibox.widget.textbox('')
54 local function update()
60 btc = parse(get(btc_url))
61 doge = parse(get(doge_url))
64 price_now.btc = tonumber(btc["subtotal"]["amount"])
65 price_now.doge = tonumber(doge["return"]["markets"]["DOGE"]["lasttradeprice"])
66 price_now.doge = string.format("%.4f", price_now.btc * price_now.doge)
73 newtimer("ccurr", timeout, update)
78 return setmetatable(ccurr, { __call = function(_, ...) return worker(...) end })