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
41 local function update()
42 btc = parse(get("https://coinbase.com/api/v1/prices/buy"))
44 btc = tonumber(btc["subtotal"]["amount"])
45 btc_display = "$" .. btc
49 doge = parse(get("http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=132"))
51 doge = tonumber(doge["return"]["markets"]["DOGE"]["lasttradeprice"])
52 doge_display = string.format("$%.4f", btc * doge)
56 prices = btc_display .. " " .. doge_display
58 prices_now.prices = prices
64 newtimer("acw", timeout, update)
69 return setmetatable(acw, { __call = function(_, ...) return worker(...) end })