Or as a complete solution: http://code.google.com/p/pyroscope/wiki … y_to_conky
Of course, that's only what's still loaded in the client, i.e. excluding the upload for any items you deleted. I hope to come around to record some statistics in RRD archives soon, then that's solved, too.
]]>I am in the process of learning python so be nice
Script Info:
This script collects information from the torrents in rTorrent and prints it out.
If you do not want the conky code then just use the def iterTorrents to get a dictionary of information from every torrent..
Is it possible to know how much data my rtorrent client has uploaded (seeded or served ) ??? I am new to the world of python..Please guide me .
]]>It can look like this:
Script Info:
This script collects information from the torrents in rTorrent and prints it out.
If you do not want the conky code then just use the def iterTorrents to get a dictionary of information from every torrent.
it is possible to configure it under def __init__() and make change in def __main__ if needed.(colors and other stuff)
Dependencies:
rtorrent with xmlrpc-c working.
xmlrpc2scgi.py to be in the same directory as this script.
xmlrpc2scgi.py can be downloaded at the bottom of this site: http://libtorrent.rakshasa.no/wiki/UtilsXmlrpc2scgi
.conkyrc setting
Conky needs this line in the Text part:
${execp /Path/To/Script/xmlrpc2rtorrent.py}
Set the text_buffer_size so it's not cutting the output.
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Script Version 1.1
#----
# Copyright 2010 Jonas Lindberg
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
# Contact: Jonas Lindberg <badomen02 gmail>
#----
#Script Info:
# This script collects information from the torrents in rTorrent and prints it out.
# If you do not want the conky code then just use the def iterTorrents to get a dictionary of information from every torrent.
# it is possible to configure it under def __init__() and change def __main__ if needed.
#Dependencies:
# rtorrent with xmlrpc-c working.
# xmlrpc2scgi.py to be in the same directory as this script.
# xmlrpc2scgi.py can be downloaded at the bottom of this site: http://libtorrent.rakshasa.no/wiki/UtilsXmlrpc2scgi
#.conkyrc setting
# Conky needs this line in the Text part:
# ${execp ~/Dokument/programmering/workspace/prjXMLrpc2scgi/src/xmlrpc2rtorrent.py}
# Set the text_buffer_size so it's not cutting the output.
from __future__ import print_function
from xmlrpc2scgi import do_scgi_xmlrpc_request_py
import socket
class TorrentInfo():
def __init__(self):
# Change settings here.
self.rpcSocketPath='/home/jonas/rtorrent_rpc/rpc.socket'
self.visible=6
# Just one of them can be true at the same time. if all is False then Just Total Down/Up will be shown.
self.showActiveTorrents=False
self.showClosedTorrents=False
self.showActAndCloTorrents=True
self.showDownTorrents=False
self.showUpTorrents=False
self.showDowUpTorrents=False
self.maxNameLength=40
# Replacing a color with an empty string '' will show your default Conky color.
self.activeColor = 'green'
self.closedColer = 'red'
self.txtColor = 'white'
self.downColor = 'orange'
self.upColor = 'brown'
self.totalColor = 'purple'
self.totalDoUpColor = 'LightGreen'
self.timeColor = 'grey'
self.lineColor = 'cyan'
self.procentColor ='yellow'
self.receivedColor = 'LightBlue'
# Do not change this:
self.countVisible = 1
self.countLines=0
self.totalUpSpeed=0
self.totalDownSpeed=0
self.rTorrentOff=False
def iterTorrents(self):
""" A iterator that returns a dictionary with information from every torrent in rTorrent. """
self.params=('default', 'd.get_name=','d.get_up_rate=','d.get_down_rate=','d.get_completed_chunks=','d.get_size_chunks=','d.get_size_bytes=','d.get_bytes_done=','d.is_active=')
self.dictKey=('name','up_rate','down_rate','done','size','total_bytes','bytes_done','is_active')
try:
self.lolRtorrents = do_scgi_xmlrpc_request_py(self.rpcSocketPath, 'd.multicall',self.params)
except socket.error:
self.rTorrentOff=True
pass
else:
self.lodTorrents=[]
for self.torrent in self.lolRtorrents:
self.lodTorrents.append(dict(zip(self.dictKey,self.torrent)))
for self.torrent in self.lodTorrents:
yield self.torrent
def collectTorrentInfo(self,torrent):
"""Collects information from the torrent.
This must be called for every torrent"""
self.totalUpSpeed+=torrent['up_rate']
self.totalDownSpeed+=torrent['down_rate']
self.fProcentDone=float(torrent['bytes_done'])/float(torrent['total_bytes'])*100
self.name=torrent['name']
self.downRate=float(torrent['down_rate']) / 1024
self.upRate=float(torrent['up_rate']) / 1024
self.totalBytes=float(torrent['total_bytes']) / 1024 / 1024
self.receivedMB=float(torrent['bytes_done']) / 1024 / 1024
self.isActive=torrent['is_active']
def __showTorrentInfo(self):
""" Is colled from showTorrentInfo to display the correct torrents specified in __init__. """
if self.countVisible<=self.visible:
self.countVisible+=1
if self.isActive:
print('${{color {0}}}Active:${{color {1}}} {2:.{3}s}'.format(self.activeColor,self.txtColor,self.name,self.maxNameLength), end='\n')
else:
print('${{color {0}}}Closed:${{color {1}}} {2:.{3}s}'.format(self.closedColer,self.txtColor,self.name,self.maxNameLength), end='\n')
print('${{color {0}}}Down:${{color {1}}} {2:.1f} KB/s'.format(self.downColor,self.txtColor,self.downRate), end='\n')
print('${{color {0}}}Up:${{color {1}}} {2:.1f} KB/s'.format(self.upColor,self.txtColor,self.upRate), end='\n')
print('${{color {0}}}Received:${{color {1}}} {2:.1f} MB'.format(self.receivedColor,self.txtColor,self.receivedMB))
print('${{color {0}}}Total:${{color {1}}} {2:.1f} MB'.format(self.totalColor,self.txtColor,self.totalBytes) ,end='\n')
print('${{color {0}}}Done:${{color {1}}} {2:.2f}%'.format(self.procentColor,self.txtColor,self.fProcentDone))
def showTorrentInfo(self):
""" Shows the torrent that you have specified in __init__. """
if self.showActiveTorrents:
if self.isActive:
self.__showTorrentInfo()
elif self.showClosedTorrents:
if not self.isActive:
self.__showTorrentInfo()
elif self.showActAndCloTorrents:
self.__showTorrentInfo()
elif self.showDownTorrents and self.downRate!=0:
self.__showTorrentInfo()
elif self.showUpTorrents and self.upRate!=0:
self.__showTorrentInfo()
elif self.showDowUpTorrents and (self.upRate!=0 or self.downRate!=0):
self.__showTorrentInfo()
def ShowTimeLeft(self,torrent):
""" Calls __ShowTimeLeft() just when needed. """
if (self.showActiveTorrents or self.showActAndCloTorrents) and self.countVisible<=self.visible:
if self.isActive:
self.__ShowTimeLeft(torrent)
elif self.showDownTorrents and self.downRate!=0 and self.countVisible<=self.visible:
self.__ShowTimeLeft(torrent)
elif self.showDowUpTorrents and self.downRate!=0:
self.__ShowTimeLeft(torrent)
def __ShowTimeLeft(self,torrent):
if torrent['total_bytes'] != torrent['bytes_done'] and (torrent['down_rate'] / 512) !=0:
if (float(torrent['down_rate']) / 1024) >= 0.4:
self.seconds_left = (torrent['total_bytes'] - torrent['bytes_done']) / ((torrent['down_rate'] / 512) * 512)
self.seconds = self.seconds_left % 60
self.minutes = self.seconds_left / 60 % 60
self.hours = self.seconds_left / 60 / 60 % 24
self.days = self.seconds_left / 60 / 60 / 24
if self.seconds == 60:
self.minutes+=1
self.seconds = 0
if self.minutes == 60:
self.hours+=1
self.minutes = 0
print('${{color {0}}}Countdown: ${{color {1}}}{2:02d}:{3:02d}:{4:02d}:{5:02d}'.format(self.timeColor,self.txtColor,self.days,self.hours,self.minutes,self.seconds))
def showTotalSpeed(self):
""" Shows the total upload and download speed """
if not self.rTorrentOff:
self.totalDownSpeedKB=float(self.totalDownSpeed)/1024
self.totalUpSpeedKB=float(self.totalUpSpeed)/1024
print('${{color {0}}}Total Down/Up:${{color {1}}} {2:.1f}/{3:.1f} KB/s'.format(self.totalDoUpColor,self.txtColor,self.totalDownSpeedKB,self.totalUpSpeedKB),end='\n')
def showLine(self):
""" Shows the line and makes shore that the liens just show up for the visible torrents."""
if self.countLines < self.countVisible-1:
self.countLines+=1
print('${{color {0}}}-----'.format(self.lineColor))
def main():
Ti=TorrentInfo()
for torrent in Ti.iterTorrents():
Ti.collectTorrentInfo(torrent)
Ti.showTorrentInfo()
Ti.ShowTimeLeft(torrent)
Ti.showLine()
Ti.showTotalSpeed()
if __name__ == "__main__":
main()
Edit: I changed Procent to Done. >> Done: 8.6%
Edit: Updated the script: Added more config options.
In the post i did 03 nov 2008, 15:10 in this(swidish) thread:
http://ubuntu-se.org/phpBB3/viewtopic.php?f=19&t=30454
That code makes it possible to see remaining time and to specify different color in the output like
printf ("${color red}%.15s ", name)
will print the name of the torrent in red and show the 15 first characters.
But to use it you have to change your 5. to
${execpi 1 ~/something.sh ~/.rtorrent_rpc/xmlrpc2scgi.py ~/.rtorrent_rpc/rpc.socket}
or:
${execp ~/something.sh ~/.rtorrent_rpc/xmlrpc2scgi.py ~/.rtorrent_rpc/rpc.socket}
Else you will not get the text coloring.
And just a note, the time interval for execi/execpi can't be less then update_interval in configuration.
And if the time interval is set to 3 seconds then the time left will not be more exact than that, but it is possible to comment away the seconds and just show hour and minutes.
I have not tested the code with conky > 1.6 so i don't know how it works now and I am using Ubuntu, not Arche.
(no flame war, I have heard a lot of good things about Arche Linux)
oew: maybe you feel like trying it out and translate some parts of the code if it looks like it's still working and post it here. Don't ask me way some variables is in Swedish... I just don't know
]]>- xmlstarlet command not found
I am also getting the same error...
]]>- xmlstarlet command not found
- newline error after DOCTYPE declaration
any hint on how to fix this problem?
]]>i have got wtorrent front end running, which requires scgi_port to be set, and when i set this i cannot use scgi_local. is there a way i can have both the wtorrent webui and be able to have my stats in conky.
thanks Markp1989
]]>test -S "$2" &&
It isn't verbose at all so it doesn't help much anyway, and it causes a problem if instead of the local rpc.socket you're using a scgi port, like scgi://localhost:33000 (which is often for those that use an additional web interface to rtorrent). Also a thing that might be causing a problem, add text_buffer_size <some big number> otherwise the text will be cut in half, you can (and should) also uncomment the
if(++j<=4)
part of the script so you can limit the amount of torrents that are getting displayed.
]]>How would I just display "Active" torrents and not all torrents in conky?
]]>#!/usr/bin/env python
import sys
from deluge.ui.client import sclient
from time import sleep
# Connect to Deluge core
sclient.set_core_uri()
# Loop forever
while sclient.connected():
torrent_ids = sclient.get_session_state() # Make sure we keep track of all torrents
print "^fg(lightblue)Torrents", # Print Torrents without a newline
for id in torrent_ids: # Loop through torrents and get status of each and then pretty print it all for dzen
info = sclient.get_torrent_status(id, ['name', 'progress', 'download_payload_rate', 'total_done', 'total_size', 'ratio'])
if info['progress'] == 100: # Use a shorter format
if len(info['name']) > 10:
info['name'] = info['name'][0:8] + ".."
print "^fg(white)| ^fg(grey50)\"" + info['name'] + "\" " + str(round(info['ratio'], 2)),
else:
if len(info['name']) > 20:
info['name'] = info['name'][0:18] + ".."
print "^fg(white)| ^fg(grey50)\"^fg(white)" + info['name'] + "^fg(grey50)\" ^fg(lightblue)" + str(info['total_done'] / 1000000) + "^fg(grey50)M/^fg(lightblue)" + str(info['total_size'] / 1000000) + "^fg(grey50)M (^fg(lightblue)" + str(round(info['progress'], 1)) + "^fg(grey50)%) ^fg(white)^i(ICONSFOLDERGOESHERE/net_down_03.xbm) ^fg(lightblue)" + str(round(info['download_payload_rate'] / 1000, 1)) + "^fg(grey50)K/s",
print # Print newline so dzen updates
sys.stdout.flush()
sleep(2)