From 52e9b72217be855c57c8a0c89b506e648eaaccd2 Mon Sep 17 00:00:00 2001 From: Joerg Thalheim Date: Fri, 24 Nov 2017 12:19:12 +0000 Subject: [PATCH] btc: remove synchronous variant and dead code --- contrib/btc_all.lua | 12 +++------ contrib/btc_linux.lua | 57 ------------------------------------------- 2 files changed, 3 insertions(+), 66 deletions(-) delete mode 100644 contrib/btc_linux.lua diff --git a/contrib/btc_all.lua b/contrib/btc_all.lua index 5bf40f8..2c60f72 100644 --- a/contrib/btc_all.lua +++ b/contrib/btc_all.lua @@ -18,11 +18,11 @@ local string = { -- Btc: provides current bitcoin price -- vicious.widgets.btc -local btc_linux = {} +local btc_all = {} -- {{ Bitcoin widget type -function btc_linux.async(format, warg, callback) +function btc_all.async(format, warg, callback) -- Default values if not warg then warg = "usd" end @@ -48,10 +48,4 @@ function btc_linux.async(format, warg, callback) end -- }}} --- {{ Bitcoin widget type -local function worker(format, warg) - btc_linux.async(format, warg, function(data) return data end) -end --- }}} - -return setmetatable(btc_linux, { __call = function(_, ...) return worker(...) end }) +return btc_all diff --git a/contrib/btc_linux.lua b/contrib/btc_linux.lua deleted file mode 100644 index 5bf40f8..0000000 --- a/contrib/btc_linux.lua +++ /dev/null @@ -1,57 +0,0 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2017, 0x5b ---------------------------------------------------- - --- {{{ Grab environment -local setmetatable = setmetatable -local pcall = pcall -local helpers = require("vicious.helpers") -local spawn = require("awful.spawn") -local json = require("json") -local string = { - sub = string.sub, - upper = string.upper, -} --- }}} - - --- Btc: provides current bitcoin price --- vicious.widgets.btc -local btc_linux = {} - - --- {{ Bitcoin widget type -function btc_linux.async(format, warg, callback) - -- Default values - if not warg then warg = "usd" end - - local btc = { ["{price}"] = "N/A" } - local currency_code = string.upper(warg) - local url = "https://api.coindesk.com/v1/bpi/currentprice/" .. currency_code .. ".json" - local cmd = "curl "..helpers.shellquote(url) - - -- {{ Checking response - local function parse(response) - -- If 'response' is not json, 'json.decode' will return Error - local status, data = pcall(function() return json.decode(response) end) - if not status or not data then - return btc - end - - btc["{price}"] = string.sub(data["bpi"][currency_code]["rate"], 0, -3) - return btc - end - -- }} - - spawn.easy_async(cmd, function(stdout) callback(parse(stdout)) end) -end --- }}} - --- {{ Bitcoin widget type -local function worker(format, warg) - btc_linux.async(format, warg, function(data) return data end) -end --- }}} - -return setmetatable(btc_linux, { __call = function(_, ...) return worker(...) end })