mirror of https://github.com/lcpz/lain.git
wiki restructured; moved widgets/contrib/ccurr to abase/use case examples/bitcoin because Crypty API is dead and Coinbase API V1 -> V2
This commit is contained in:
parent
4003d09639
commit
0a6274b434
|
@ -1,82 +0,0 @@
|
|||
|
||||
--[[
|
||||
|
||||
Licensed under GNU General Public License v2
|
||||
* (c) 2014, Aaron Lebo
|
||||
|
||||
--]]
|
||||
|
||||
local newtimer = require("lain.helpers").newtimer
|
||||
local json = require("lain.util").dkjson
|
||||
|
||||
local wibox = require("wibox")
|
||||
|
||||
local string = { format = string.format }
|
||||
local tonumber = tonumber
|
||||
|
||||
-- Crypto currencies widget
|
||||
-- lain.widgets.contrib.ccurr
|
||||
local ccurr = {}
|
||||
|
||||
-- Currently gets
|
||||
-- * BTC/USD
|
||||
-- * 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
|
||||
|
||||
local function get(url)
|
||||
local f = io.popen('curl -m 5 -s "' .. url .. '"')
|
||||
if not f then
|
||||
return 0
|
||||
else
|
||||
local s = f:read("*all")
|
||||
f:close()
|
||||
return s
|
||||
end
|
||||
end
|
||||
|
||||
local function parse(j)
|
||||
local obj, pos, err = json.decode(j, 1, nil)
|
||||
if err then
|
||||
return nil
|
||||
else
|
||||
return obj
|
||||
end
|
||||
end
|
||||
|
||||
local function worker(args)
|
||||
local args = args or {}
|
||||
local timeout = args.timeout or 600
|
||||
local btc_url = args.btc_url or "https://coinbase.com/api/v1/prices/buy"
|
||||
local doge_url = args.doge_url or "http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=132"
|
||||
local settings = args.settings or function() end
|
||||
|
||||
ccurr.widget = wibox.widget.textbox('')
|
||||
|
||||
local function update()
|
||||
price_now = {
|
||||
btc = "N/A",
|
||||
doge = "N/A"
|
||||
}
|
||||
|
||||
btc = parse(get(btc_url))
|
||||
doge = parse(get(doge_url))
|
||||
|
||||
if btc and doge then
|
||||
price_now.btc = tonumber(btc["subtotal"]["amount"])
|
||||
price_now.doge = tonumber(doge["return"]["markets"]["DOGE"]["lasttradeprice"])
|
||||
price_now.doge = string.format("%.4f", price_now.btc * price_now.doge)
|
||||
end
|
||||
|
||||
widget = ccurr.widget
|
||||
settings()
|
||||
end
|
||||
|
||||
newtimer("ccurr", timeout, update)
|
||||
|
||||
return ccurr.widget
|
||||
end
|
||||
|
||||
return setmetatable(ccurr, { __call = function(_, ...) return worker(...) end })
|
2
wiki
2
wiki
|
@ -1 +1 @@
|
|||
Subproject commit c4e5537b9502894954c825fad4fd90d9abd3b29d
|
||||
Subproject commit 851d58df3ac1ea7b06458809cdde0c8a64d8c266
|
Loading…
Reference in New Issue