All pastes #52363 Raw Edit

Untitled

public text v1 · immutable
#52363 ·published 2006-04-30 12:49 UTC
rendered paste body
#!/usr/bin/env python
#
# anrxc[at]hi.t-com.hr
#
# sinfo.py, System Information script for xchat (IRC client).
#
# More information about python plugin interface for xchat
# can be found here <http://labix.org/xchat-python>.

# sys to do: - DE/WM  ... maybe mem and disk usage
# media to do: - graphic card, resolution(+dpi?)
# general to do: do we need some fancy colors?

__module_name__ = "sinfo"
__module_version__ = "0.1"
__module_description__ = "System Information script for xchat, written by anrxc, lastfm by b4d."

import xchat, commands, string, re
from urllib import urlopen

#Your last.fm username:
user='b4d'

# system info
def sysinf(word, word_eol, userdata):
    # user@host
    u = commands.getoutput('whoami')
    h = commands.getoutput('hostname')
    uh = u+'@'+h

    # OS
    comm = 'uname -sr'
    uname = commands.getoutput(comm)

    # Distro
    try:
        catcomm = 'cat /etc/*sion'
        distro = commands.getoutput(catcomm)
    except: distro = 'Unknown'

    # Proc
    cpu = string.split(commands.getoutput('cat /proc/cpuinfo | grep "model name"'), ':')
    cpuinfo = cpu[1]

    # Proc speed
    mhz = string.split(commands.getoutput('cat /proc/cpuinfo | grep "cpu MHz"'), ':')
    speed = mhz[1].split('.')
    speed = speed[0]

    # uptime
    up = commands.getoutput("uptime")
    splitit = string.split(up)
    if splitit[3] == 'days,' or splitit[3] == 'day,':
        uptime = splitit[2]+' '+splitit[3]+' '+splitit[4][0:-1]+' hours'
    else:
        uptime = splitit[2][0:-1]+' hours'

    # DE / WM, stolen, or better to say retrived (i helped in the first place :P)
    # from myinfo.pl written by Zeljko Mitrovic
    #dewm = {'fvwm' : 'FVWM',
    #        'icewm': 'IceWM',
    #        'enlightenment' : 'Enlightenment',
    #        'startkde' : 'KDE',
    #        'wmaker' : 'WindowMaker',
    #        'blackbox' : 'Blackbox',
    #        'fluxbox' : 'Fluxbox',
    #        'gnome-panel' : 'GNOME',
    #        'xfce4-panel' : 'XFCE'}
    #for key, data in dewm.items():
    #    pgrep = commands.getoutput('pgrep %s | wc -l' % key)

    # client version
    version = xchat.get_info('version')
    
    # put it all together and send to the channel
    buildinfo = uh+' | OS: '+uname+', Distro: '+distro+' | CPU:'+cpuinfo+', MHz:'+speed+' | Uptime: '+uptime+' | Client: XChat-'+version

    # this is in no way needed, but let it be
    sysinfo = buildinfo
    
    xchat.command('say %s' % sysinfo)

    # show but don't send to the channel
    #xchat.prnt(sysinfo)

    return xchat.EAT_ALL

# media info
def mediainf(word, word_eol, userdata):
    xchat.command('say this doesnt do anything yet')
    
#lastfm info by b4d, www.baccic.be
def lastfm(word, word_eol, userdata):
    # open the site
    last = urlopen("http://ws.audioscrobbler.com/1.0/user/%s/recenttracks.rss" % user)
    # read and close
    readit = last.read()
    last.close()
    # what we are looking for
    played = re.compile('<title>(.*?)</title>', re.DOTALL)
    # store the data
    info = played.findall(readit)[:6]
    for song in info:
        try: xchat.command('say %s' % song)
        except UnboundLocalError: pass
    
    return xchat.EAT_ALL

# amaroK now playing
def amaroknp(word, word_eol, userdata):
    dcopreq = 'dcop amarok player'
    test = string.split(commands.getoutput(dcopreq))
    if test[0] in ('ERROR:','call','object'):
        np = 'Is amaroK running?'
    else:
        track = commands.getoutput('%s nowPlaying' % dcopreq)
        album = commands.getoutput('%s album' % dcopreq)
        time  = commands.getoutput('%s totalTime' % dcopreq)
        if track == '':
            np = 'Is amaroK running?'
        else:
            if album == '':
                np = 'aK: '+track+' - (N/A) - '+time
            else:
                np = 'aK: '+track+' - ('+album+') - '+time
    
    xchat.command('say %s' % np)
    
    return xchat.EAT_ALL

# system info command
xchat.hook_command("sinfo", sysinf)

# media info command
xchat.hook_command("smedia", mediainf)

# lastfm tracks
xchat.hook_command("lastfm", lastfm)

# amarok info command
xchat.hook_command("ak", amaroknp)

print "sinfo.py loaded"
# EOF