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.
3 Licensed under GNU General Public License v2
8 local newtimer = require("lain.helpers").newtimer
9 local wibox = require("wibox")
10 local json = require("dkjson")
12 -- acw (awesome crypto widget)
13 -- diplays BTC/USD and DOGE/USD using Coinbase and Cryptsy APIs
14 -- requires http://dkolf.de/src/dkjson-lua.fsl/home
15 -- based upon http://awesome.naquadah.org/wiki/Bitcoin_Price_Widget
16 -- lain.widgets.contrib.acw
18 acw = {widget=wibox.widget.textbox('')}
20 local function get(url)
21 f = io.popen('curl -m 5 -s "' .. url .. '"')
22 if (not f) then return 0 end
26 local function parse(j)
27 local obj, pos, err = json.decode (j, 1, nil)
28 if err thenfunction worker(args)
36 local args = args or {}
37 local timeout = args.timeout or 600
38 local settings = args.settings or function() end
40 local function update()
41 btc = parse(get("https://coinbase.com/api/v1/prices/buy"))
43 btc = tonumber(btc["subtotal"]["amount"])
44 btc_display = "$" .. btc
48 doge = parse(get("http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=132"))
50 doge = tonumber(doge["return"]["markets"]["DOGE"]["lasttradeprice"])
51 doge_display = string.format("$%.4f", btc * doge)
55 prices = btc_display .. " " .. doge_display
57 prices_now.prices = prices
63 newtimer("acw", timeout, update)
68 return setmetatable(acw, { __call = function(_, ...) return worker(...) end })