From cf1a6e745513eefdcff592d1b7ea43bb616bb18a Mon Sep 17 00:00:00 2001 From: aaron-lebo Date: Mon, 10 Feb 2014 03:02:14 -0600 Subject: [PATCH 1/3] Create acw.lua --- widgets/contrib/acw.lua | 69 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 widgets/contrib/acw.lua diff --git a/widgets/contrib/acw.lua b/widgets/contrib/acw.lua new file mode 100644 index 0000000..0c3ae3f --- /dev/null +++ b/widgets/contrib/acw.lua @@ -0,0 +1,69 @@ +-[[ + + Licensed under GNU General Public License v2 + * (c) 2014, Aaron Lebo + +--]] + +local newtimer = require("lain.helpers").newtimer +local wibox = require("wibox") +local json = require("dkjson") + +-- acw (awesome crypto widget) +-- diplays BTC/USD and DOGE/USD using Coinbase and Cryptsy APIs +-- requires http://dkolf.de/src/dkjson-lua.fsl/home +-- based upon http://awesome.naquadah.org/wiki/Bitcoin_Price_Widget +-- lain.widgets.contrib.acw + +acw = {widget=wibox.widget.textbox('')} + +local function get(url) + f = io.popen('curl -m 5 -s "' .. url .. '"') + if (not f) then return 0 end + return f:read("*all") +end + +local function parse(j) + local obj, pos, err = json.decode (j, 1, nil) + if err thenfunction worker(args) + return nil + else + return obj + end +end + +function worker(args) + local args = args or {} + local timeout = args.timeout or 600 + local settings = args.settings or function() end + + + local function update() + btc = parse(get("https://coinbase.com/api/v1/prices/buy")) + if btc then + btc = tonumber(btc["subtotal"]["amount"]) + btc_display = "$" .. btc + else + btc_display = "N/A" + end + doge = parse(get("http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=132")) + if doge and btc then + doge = tonumber(doge["return"]["markets"]["DOGE"]["lasttradeprice"]) + doge_display = string.format("$%.4f", btc * doge) + else + doge_display = "N/A" + end + prices = btc_display .. " " .. doge_display + prices_now = {} + prices_now.prices = prices + + widget = acw.widget + settings() + end + + newtimer("acw", timeout, update) + + return acw.widget +end + +return setmetatable(acw, { __call = function(_, ...) return worker(...) end }) From 700812653cc2b56d7b6f6c22d597f0c0064370dd Mon Sep 17 00:00:00 2001 From: aaron-lebo Date: Mon, 10 Feb 2014 03:06:50 -0600 Subject: [PATCH 2/3] Update acw.lua --- widgets/contrib/acw.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/widgets/contrib/acw.lua b/widgets/contrib/acw.lua index 0c3ae3f..c06de57 100644 --- a/widgets/contrib/acw.lua +++ b/widgets/contrib/acw.lua @@ -37,7 +37,6 @@ function worker(args) local timeout = args.timeout or 600 local settings = args.settings or function() end - local function update() btc = parse(get("https://coinbase.com/api/v1/prices/buy")) if btc then From 917bcb2135636c547ec987c5cdc57c212a4efaed Mon Sep 17 00:00:00 2001 From: Aaron Lebo Date: Mon, 10 Feb 2014 05:49:49 -0600 Subject: [PATCH 3/3] Moved acw from single file to folder. --- widgets/contrib/{acw.lua => acw/init.lua} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename widgets/contrib/{acw.lua => acw/init.lua} (100%) diff --git a/widgets/contrib/acw.lua b/widgets/contrib/acw/init.lua similarity index 100% rename from widgets/contrib/acw.lua rename to widgets/contrib/acw/init.lua