Page 2 of 20 FirstFirst 123412 ... LastLast
Results 11 to 20 of 195

Thread: Conky Pidgin Python Script

  1. #11
    Join Date
    Aug 2006
    Location
    /..
    Beans
    269
    Distro
    Lubuntu 12.10 Quantal Quetzal

    Re: Conky Pidgin Python Script

    Nice. It could really use an "ignore group" option though instead of just individual buddies, and sort the buddies within the groups instead of only by group.

    Also, modified to be able to change the "Online" and "Offline" strings with -O and -F or --onlinestring and --offlinestring:
    Code:
    #!/usr/bin/python
    # -*- coding: utf-8 -*-
    ###############################################################################
    # conkyPidgin.py is a simple python script to display 
    # details of pidgin buddies, for use in conky.
    #
    #  Author: Kaivalagi
    # Created: 03/11/2008
    # Modifications:
    #    03/11/2008    Added --onlineonly option to only show online buddies in the list
    #    03/11/2008    Added --ignorelist to handle ignoring unwanted pidgin buddy output
    #    03/11/2008    Added --includelist to handle including only wanted pidgin buddy output
    #    03/11/2008    Updated to handle buddy group and status_messages
    #    03/11/2008    Updated to display a status of "Chatting" when the buddy is messaging
    
    #    04/11/2008    Status message Now html striped from the text
    
    import sys, traceback
    try:
        import dbus
        DBUS_AVAIL = True
    except ImportError:
        # Dummy D-Bus library
        class _Connection:
            get_object = lambda *a: object()
        class _Interface:
            __init__ = lambda *a: None
            ListNames = lambda *a: []
        class Dummy: pass
        dbus = Dummy()
        dbus.Interface = _Interface
        dbus.service = Dummy()
        dbus.service.method = lambda *a: lambda f: f
        dbus.service.Object = object
        dbus.SessionBus = _Connection
        DBUS_AVAIL = False
    
    import re
    from htmlentitydefs import name2codepoint
    from optparse import OptionParser
    
    class CommandLineParser:
    
        parser = None
    
        def __init__(self):
    
            self.parser = OptionParser()
            self.parser.add_option("-t", "--template", dest="template", type="string", metavar="FILE", help=u"Template file determining the format for each buddy's data. Use the following placeholders: <name>, <alias>, <group>, <status>, <status_message>.")
            self.parser.add_option("-o", "--onlineonly", dest="onlineonly", default=False, action="store_true", help=u"Only show online buddies")
            self.parser.add_option("-i", "--ignorelist", dest="ignorelist", type="string", metavar="LIST", help=u"A comma delimited list of names or aliases to ignore. Partial text matches on name or alias will be ignored if found")
            self.parser.add_option("-I", "--includelist", dest="includelist", type="string", metavar="LIST", help=u"A comma delimited list of names or aliases to include. Partial text matches on name or alias will be included if found. The ignorelist, if used, takes precedence. if this list is omitted all buddies will be included unless ignored.")
            self.parser.add_option("-v", "--verbose", dest="verbose", default=False, action="store_true", help=u"Request verbose output, not a good idea when running through conky!")
            self.parser.add_option("-V", "--version", dest="version", default=False, action="store_true", help=u"Displays the version of the script.")
            self.parser.add_option("-O", "--onlinestring", dest="onlinestring", type="string", metavar="string", help=u"String for \"Online\"")
    	self.parser.add_option("-F", "--offlinestring", dest="offlinestring", type="string", metavar="string", help=u"String for \"Offline\"")
    
        def parse_args(self):
            (options, args) = self.parser.parse_args()
            return (options, args)
    
        def print_help(self):
            return self.parser.print_help()
    
    class BuddyData:
        def __init__(self, name, alias, group, status, status_message):
            self.name = name
            self.alias = alias
            self.group = group
            self.status = status
            self.status_message = status_message
    
        def __cmp__(self, other):
            return cmp(self.group, other.group)
        
        def __str__(self):
            return str(self.name+"("+self.alias+")")
            
    class ConkyPidgin:
        
        def __init__(self, options):
            self.options = options
            
        def testDBus(self, bus, interface):
            obj = bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus')
            dbus_iface = dbus.Interface(obj, 'org.freedesktop.DBus')
            avail = dbus_iface.ListNames()
            return interface in avail
    
        def getTemplateOutput(self, template, name, alias, group, status, status_message):
            
            try:
                
                output = template
        
                output = output.replace("<name>",name)
                output = output.replace("<alias>",alias)
                output = output.replace("<group>",group)
                output = output.replace("<status>",status)
                output = output.replace("<status_message>",status_message)
    
                # get rid of any excess crlf's
                output = output.rstrip(" \n")
                
                return output
            
            except Exception,e:
                self.logError("getTemplateOutput:Unexpected error:" + e.__str__())
                return ""
        
        def getbuddyData(self):
            
            buddyDataList = []
            
            try:
                    
                bus = dbus.SessionBus()
    
                if self.testDBus(bus, 'im.pidgin.purple.PurpleService'):
                    
                        self.logInfo("Setting up dbus interface")
                        
                        remote_object = bus.get_object("im.pidgin.purple.PurpleService","/im/pidgin/purple/PurpleObject")
                        iface = dbus.Interface(remote_object, "im.pidgin.purple.PurpleService")
                        
                        self.logInfo("Calling dbus interface for IM data")
                            
                        # Iterate through every active account
                        for acctID in iface.PurpleAccountsGetAllActive():
                            
                            # get all the buddies associated with that account
                            buddies = iface.PurpleFindBuddies(acctID,"")
    
                            for buddyid in buddies:
                                
                                # get initial data
                                alias = iface.PurpleBuddyGetAlias(buddyid)
                                name = iface.PurpleBuddyGetName(buddyid)
                                online = iface.PurpleBuddyIsOnline(buddyid)
                                
                                if self.ignoreBuddy(name, alias) == False:
    
                                    if self.includeBuddy(name, alias) == True:
                                        
                                        # determine whether to show this buddies details
                                        if online == 1 or self.options.onlineonly == False:
                                            
                                            # get all the extra details we want
                                            groupid = iface.PurpleBuddyGetGroup(buddyid)
                                            group = iface.PurpleGroupGetName(groupid)
    
    					if self.options.onlinestring == None:
    						self.options.onlinestring = "Online"
    					if self.options.offlinestring == None:
    						self.options.offlinestring = "Offline"
                                                                                    
                                            if online == 1:
                                                status = self.options.onlinestring
                                            else:
                                                status = self.options.offlinestring
                                            
                                            # status message
                                            presenceid = iface.PurpleBuddyGetPresence(buddyid)
                                            statusid = iface.PurplePresenceGetActiveStatus(presenceid)
                                            status_message = self.getCleanText(iface.PurpleStatusGetAttrString(statusid, "message")) # needed for google encoded text
                                            
                                            if self.isBuddyChatting(name,iface):
                                                status = "Chatting"
    
                                            buddyData = BuddyData(name, alias, group, status, status_message)
                                            buddyDataList.append(buddyData)
    
                        # tidy up
                        del iface
                        del remote_object
                        del bus
                
                # sort by group
                buddyDataList.sort()
                
                return buddyDataList
                    
            except Exception, e:
                self.logError("Issue calling the dbus service:"+e.__str__())
            
        def getOutputText(self):
            
            if self.options.template == None:
                
                # create default template
                template = "<alias> (<group>) - <status>\n\t<status_message>"
            else:
                # load the template file contents
                try:
                    fileinput = open(self.options.template)
                    template = fileinput.read()
                    fileinput.close()
                except:
                    self.logError("Template file no found!")
                    sys.exit(2)
    
            try:
                    
                buddyDataList = self.getbuddyData()
                
                for buddyData in buddyDataList:
                    
                    # output pidgin buddy data using the template
                    output = self.getTemplateOutput(template, buddyData.name, buddyData.alias, buddyData.group, buddyData.status, buddyData.status_message)
                    print output.encode("utf-8")
            
            except SystemExit:
                self.logError("System Exit!")
                return u""
            except Exception, e:
                traceback.print_exc()
                self.logError("Unknown error when calling getOutputText:" + e.__str__())
                return u""
    
        def isBuddyChatting(self,name,iface):
            imids = iface.PurpleGetIms()
            for imid in imids:
                convname = iface.PurpleConversationGetName(imid)
                if convname == name:
                    return True
                
            return False
        
        def ignoreBuddy(self, name, alias):
            
            if self.options.ignorelist != None:
                        
                # for each text in the ignore list, should we be ignoring the buddy
                for ignore in self.options.ignorelist.split(","):
                    # has the buddy been found in the list item
                    if name.find(ignore) != -1 or alias.find(ignore) != -1:
                        return True
            
                return False
            
            else:
                return False
    
        def includeBuddy(self, name, alias):
            
            if self.options.includelist != None:
                
                # for each text in the ignore list, should we be ignoring the buddy
                for include in self.options.includelist.split(","):
                    # has the buddy been found in the list item
                    if name.find(include) != -1 or alias.find(include) != -1:
                        return True
            
                return False
            
            else:
                return True
    
        def getCleanText(self,text):
            text = text.replace("&apos;","'") # workaround for ****** xml codes not compliant with html
            text = re.sub('<(.|\n)+?>','',text) # remove any html tags
            return re.sub('&(%s);' % '|'.join(name2codepoint), lambda m: chr(name2codepoint[m.group(1)]), text)
                       
        def logInfo(self, text):
            if self.options.verbose == True:
                print >> sys.stdout, "INFO: " + text
        
        def logError(self, text):
            print >> sys.stderr, "ERROR: " + text
            self.error = self.error + "ERROR: " + text + "\n"
            self.errorfound = True
            
    if __name__ == "__main__":
        
        parser = CommandLineParser()
        (options, args) = parser.parse_args()
    
        if options.version == True:
            print >> sys.stdout,"conkyPidgin v.2.02"
        else:
            if options.verbose == True:
                print >> sys.stdout,"*** INITIAL OPTIONS:"
                print >> sys.stdout,"    template:", options.template
                print >> sys.stdout,"    onlineonly:", options.onlineonly
                print >> sys.stdout,"    ignorelist:", options.ignorelist
                print >> sys.stdout,"    verbose:", options.verbose
                
            conkyPidgin = ConkyPidgin(options)
            conkyPidgin.getOutputText()
    Last edited by HyperHacker; November 7th, 2008 at 07:20 AM.
    $ sudo make me a sandwich

  2. #12
    Join Date
    Feb 2008
    Location
    52°38'41.6"N/1°19'43.6"E
    Beans
    Hidden!

    Re: Conky Pidgin Python Script

    Quote Originally Posted by HyperHacker View Post
    Nice. It could really use an "ignore group" option though instead of just individual buddies, and sort the buddies within the groups instead of only by group.

    Also, modified to be able to change the "Online" and "Offline" strings with -O and -F or --onlinestring and --offlinestring
    All good suggestions, I'll take a look at the weekend. Edit: Alright so I've done it in 30 minutes before going to work

    The includelist and ignorelist options can easily be used for groups instead.

    I assume you want to set custom strings of online/offline status so you can use custom fonts and display symbols instead?
    Last edited by kaivalagi; November 7th, 2008 at 10:17 AM.

  3. #13
    Join Date
    Feb 2008
    Location
    52°38'41.6"N/1°19'43.6"E
    Beans
    Hidden!

    Re: Conky Pidgin Python Script

    UPDATE

    Changes below:

    • Updated --ignorelist and --includelist options to be based on group names rather than buddy names, not case sensitive now either
    • Added --onlinetext, --offlinetext and --chattingtext options to set custom text for status output
    • Updated README


    The first post is updated and the apt package will be available shortly

    Chimo

  4. #14
    Join Date
    Aug 2006
    Location
    /..
    Beans
    269
    Distro
    Lubuntu 12.10 Quantal Quetzal

    Re: Conky Pidgin Python Script

    Cool. It won't ignore a group named "It's-a Me", though. (I did escape the space, and it ignores other groups with apostrophes in their names.)
    $ sudo make me a sandwich

  5. #15
    Join Date
    Feb 2008
    Location
    52°38'41.6"N/1°19'43.6"E
    Beans
    Hidden!

    Re: Conky Pidgin Python Script

    Quote Originally Posted by HyperHacker View Post
    Cool. It won't ignore a group named "It's-a Me", though. (I did escape the space, and it ignores other groups with apostrophes in their names.)
    Did you put the group name in quotes e.g.

    Code:
    --ignorelist="It's-a Me"
    I have just tried it and it's fine.

    You could also just use "me"...as it will remove partial matches too

    Hope that helps

  6. #16
    Join Date
    Feb 2008
    Location
    52°38'41.6"N/1°19'43.6"E
    Beans
    Hidden!

    Re: Conky Pidgin Python Script

    UPDATE

    I've updated the script slightly, as follows:

    • Updated sorting to not be case sensitive and be ordered by status (chatting, online then offline), group then alias
    • Added webdings font to package and used for status output in example template


    The first post has been updated and the apt package is available

    Chimo
    Last edited by kaivalagi; November 10th, 2008 at 12:27 AM.

  7. #17
    Join Date
    Feb 2008
    Location
    52°38'41.6"N/1°19'43.6"E
    Beans
    Hidden!

    Re: Conky Pidgin Python Script

    UPDATE

    Updated the script as follows:

    • Added --errorlog and --infolog options to log data to a file
    • Refactored and tidied up
    • Updated README


    The first post is updated and the apt package will be available shortly

  8. #18
    Join Date
    Jan 2008
    Beans
    150
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Conky Pidgin Python Script

    seem to be having a problem. my setup seems to get cut off...


    i already have my text buffer set at 2049
    i know that it has stretched off the bottom of my screen before, but recently updated to the current one and its stops. maybe my max size is out of whack?

    Code:
    # set to yes if you want Conky to be forked in the background
    background yes
    
    cpu_avg_samples 2
    net_avg_samples 2
    
    out_to_console no
    
    # X font when Xft is disabled, you can pick one with program xfontsel
    #font 7x12
    #font 6x10
    #font 7x13
    #font 8x13
    #font 7x12
    #font *mintsmild.se*
    #font -*-*-*-*-*-*-34-*-*-*-*-*-*-*
    #font -artwiz-snap-normal-r-normal-*-*-100-*-*-p-*-iso8859-1
    
    # Use Xft?
    use_xft yes
    
    # Xft font when Xft is enabled
    xftfont Terminus:size=10
    #xftfont zekton:size=9
    
    # Text alpha when using Xft
    xftalpha 1
    
    # Use double buffering (reduces flicker, may not work for everyone)
    double_buffer yes
    
    # mail spool
    mail_spool $MAIL
    
    # Update interval in seconds
    update_interval 1
    
    # Create own window instead of using desktop (required in nautilus)
    own_window yes
    own_window_transparent yes
    own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
    own_window_type override
    
    # Use double buffering (reduces flicker, may not work for everyone)
    double_buffer yes
    
    # Minimum size of text area
    minimum_size 200 5
    maximum_width 400
    
    # Draw shades?
    draw_shades no
    
    # Draw outlines?
    draw_outline no
    
    # Draw borders around text
    draw_borders no
    
    # Stippled borders?
    stippled_borders no
    
    # border margins
    border_margin 4
    
    # border width
    border_width 10
    
    # Default colors and also border colors
    default_color white
    default_shade_color black
    default_outline_color black
    
    # colours
    color1 white
    # light blue
    color2 6892C6
    # orange
    color3 E77320
    # green
    color4 78BF39
    # red
    color5 CC0000
    # yellow
    color6 FEB212
    
    # Text alignment, other possible values are commented
    #alignment top_left
    alignment top_right
    #alignment bottom_left
    #alignment bottom_right
    
    # Gap between borders of screen and text
    gap_x 10
    gap_y 40
    
    # Add spaces to keep things from moving about?  This only affects certain objects.
    use_spacer none
    
    # Subtract file system buffers from used memory?
    no_buffers yes
    
    # set to yes if you want all text to be in uppercase
    uppercase no
    
    # none, xmms, bmp, audacious, infopipe (default is none)
    
    text_buffer_size 2048
    
    # stuff after 'TEXT' will be formatted on screen
    
    #
    #$color ${if_running rhythmbox}${execp conkyRhythmbox --template=/home/clockwork/.conkyscripts/conkyRhythmbox.template}${hr 2}${else}${font tengwar annatar:size=10}pouiduf poudaf piugf afioh${endif}
    TEXT
    ${color gold}${font Terminus:style=Bold:size=14}@ ${font Space Age:size=14}Pidgin${font}
    ${execpi 60 conkyPidgin --template=/home/clockwork/.conkyscripts/conkyPidgin.template --onlineonly --onlinetext=a --offlinetext=r --chattingtext=q --ignorelist=AIM Bots}
    Intel Pentium IV Northwood@2.4 GHz, 1 GiB RAM, 22" Samsung Monitor Ubuntu 9.04 Jaunty Jackalope
    AMD Turion 64 X2 Mobile technology @2.2GHz, 2 GiB RAM, 320 GiB HDD Windows 7 Ultimate RC1

    please remember to thank those that helped you

  9. #19
    Join Date
    Feb 2008
    Location
    52°38'41.6"N/1°19'43.6"E
    Beans
    Hidden!

    Re: Conky Pidgin Python Script

    Quote Originally Posted by cl0ckwork View Post
    seem to be having a problem. my setup seems to get cut off...


    i already have my text buffer set at 2049
    i know that it has stretched off the bottom of my screen before, but recently updated to the current one and its stops. maybe my max size is out of whack?
    You have too many online friends

    What happens when you run the script in the terminal, do you see everything you'd expect?

    Try increasing your text buffer some more?

  10. #20
    Join Date
    Jan 2008
    Beans
    150
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Conky Pidgin Python Script

    i guess i gotta cut back on my social life

    took out part of the options and increases the text buffer to 4096.
    much better

    Edit: it wont let me ignore more than 2 groups?

    Re-Edit:just used the includelist option for now
    Last edited by cl0ckwork; November 11th, 2008 at 02:10 AM.
    Intel Pentium IV Northwood@2.4 GHz, 1 GiB RAM, 22" Samsung Monitor Ubuntu 9.04 Jaunty Jackalope
    AMD Turion 64 X2 Mobile technology @2.2GHz, 2 GiB RAM, 320 GiB HDD Windows 7 Ultimate RC1

    please remember to thank those that helped you

Page 2 of 20 FirstFirst 123412 ... LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •