All pastes #808558 Raw Edit

XChat Bashfr

public python v1 · immutable
·published 2007-12-07 18:36 UTC
rendered paste body
# -*- coding: iso-8859-15 -*-import urllibimport stringimport sysimport xchat__module_name__ = "Bashfr Module"__module_version__ = "1.0"__module_description__ = "Get the requested quote"__module_author__ = "0x586e"class BashFR:        def __init__(self,QuoteID):        self.MyPage = 'http://www.bashfr.org/index.php?'        self.MyQuote = ''        self.MySource = urllib.urlopen(self.MyPage+str(QuoteID))        self.MySource = self.MySource.read()        self.IsQuote = False                self.MyMapping = {'&nbsp;':' ','&lt;':'<','&gt;':'>','&amp;':'&','&quot;':'"','&apos;':"'",'&agrave;':'à','&eacute;':'é','&egrave;':'è',        '&#039;':"'",'<br />':'','&ccedil;':'ç','&sect;':'§','&ecirc;':'ê','&deg;':'°'        }                MyLookupString = '" class="com"></span><br />'        MySecondLookup = '</div><div class="adsense">'        MyPos = string.find(self.MySource,MyLookupString)        MyPos = MyPos + len(MyLookupString)        MySecondPos = string.find(self.MySource,MySecondLookup)        try:            while (MyPos != MySecondPos):                self.MyQuote += self.MySource[MyPos]                MyPos = MyPos + 1            self.IsQuote = True        except IndexError:            self.IsQuote = False        self.removeEntity(self.MyQuote)            def removeEntity(self,MyText):        for MyChar in self.MyMapping:            MyText = MyText.replace(MyChar,self.MyMapping[MyChar])        self.MyQuote = MyText            def GetQuote(self):        return self.MyQuotedef BashFRGet(word,word_eol,userdata):    if (len(word) > 1):        MyID = word[1]        MyBash = BashFR(MyID)        if (MyBash.IsQuote):            xchat.prnt(':: Quote n°'+MyID+' ::')            xchat.prnt(MyBash.GetQuote())            xchat.prnt(':: Fin de la quote ::')        else:            xchat.prnt(':: Quote inconnue ::')    else:        xchat.prnt('Argument invalide.')    return xchat.EAT_ALL    xchat.hook_command('bashfr',BashFRGet,help="Get BashFR Quote")