Skip to content

Instantly share code, notes, and snippets.

@oranenj
Created September 10, 2014 20:16
Show Gist options
  • Save oranenj/0068e7ef739b4cf6fd13 to your computer and use it in GitHub Desktop.
Save oranenj/0068e7ef739b4cf6fd13 to your computer and use it in GitHub Desktop.
Dead-simple awesome transmission indicator using lua-transmission
function create_indicator()
local rpc = require 'transmissionrpc.client'
local utils = require 'transmissionrpc.utils'
c = rpc.new("transmission", 9091)
local UPDATE_FREQ = 5
transmission_indicator = wibox.widget.textbox()
transmission_indicator:set_text("...")
local updating = false
local update_timer = timer({ timeout = UPDATE_FREQ })
update_timer:connect_signal("timeout", function()
if updating then
return
end
updating = true
local ok, stats = pcall(function ()
return c:rpccall("session-stats")
end)
if (not ok) then
transmission_indicator:set_text("E")
error(stats)
end
local a = stats.arguments
local str = string.format("U: %s D: %s (%2d/%2d)",
utils.nice_speed(a.uploadSpeed),
utils.nice_speed(a.downloadSpeed),
a.activeTorrentCount, a.torrentCount)
transmission_indicator:set_text(str)
updating = false
end)
update_timer:start()
return transmission_indicator
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment