Example #1
0
File: care.py Project: gipi/Richie
 def __init__(self, madcow=None):
     self.google = Google()
     self.bar = [i for i in '.' * self.size]
     self.size = float(self.size)
     self.min = float(self.min)
     self.max = float(self.max)
     self.range = self.max - self.min
Example #2
0
File: care.py Project: gipi/Richie
 def __init__(self, madcow=None):
     self.google = Google()
     self.bar = [i for i in '.' * self.size]
     self.size = float(self.size)
     self.min = float(self.min)
     self.max = float(self.max)
     self.range = self.max - self.min
Example #3
0
File: care.py Project: gipi/Richie
class Main(Module):
    pattern = None
    pattern = re.compile(r'^\s*care(?:(?:[- ]?o)?[- ]?meter)?\s+(.+)\s*$',
                         re.I)
    help = 'care <#> - display a care-o-meter'
    error = 'invalid care factor'
    isnum = re.compile(r'^\s*[0-9.]+\s*$')
    sep = re.compile(r'\s*=\s*')
    numsep = re.compile(r'(\d)\s+(\d)')
    title = 'CARE-O-METER'

    # settings
    size = 40
    min = 0
    max = 100

    def __init__(self, madcow=None):
        self.google = Google()
        self.bar = [i for i in '.' * self.size]
        self.size = float(self.size)
        self.min = float(self.min)
        self.max = float(self.max)
        self.range = self.max - self.min

    def response(self, nick, args, kwargs):
        try:
            val = args[0]
            if not self.isnum.search(val):
                # try google calculator if not a number
                val = self.google.calculator(val)
                val = self.numsep.sub(r'\1\2', val)
                val = self.sep.split(val)[1]
                val = val.split()[0]
            val = float(val)

            # sanity check value
            if val < self.min:
                val = self.min
            elif val > self.max:
                val = self.max

            # create bar
            pos = int(round((self.size - 1) * ((val - self.min) / self.range)))
            bar = list(self.bar)
            bar[pos] = 'o'
            bar = ''.join(bar)
            bar = '|' + bar + '|'
            response = '%s: %s' % (self.title, bar)
            return response

        except Exception, e:
            log.warn('error in %s: %s' % (self.__module__, e))
            log.exception(e)
            return '%s: %s' % (nick, self.error)
Example #4
0
File: care.py Project: gipi/Richie
class Main(Module):
    pattern = None
    pattern = re.compile(r'^\s*care(?:(?:[- ]?o)?[- ]?meter)?\s+(.+)\s*$', re.I)
    help = 'care <#> - display a care-o-meter'
    error = 'invalid care factor'
    isnum = re.compile(r'^\s*[0-9.]+\s*$')
    sep = re.compile(r'\s*=\s*')
    numsep = re.compile(r'(\d)\s+(\d)')
    title = 'CARE-O-METER'

    # settings
    size = 40
    min = 0
    max = 100

    def __init__(self, madcow=None):
        self.google = Google()
        self.bar = [i for i in '.' * self.size]
        self.size = float(self.size)
        self.min = float(self.min)
        self.max = float(self.max)
        self.range = self.max - self.min

    def response(self, nick, args, kwargs):
        try:
            val = args[0]
            if not self.isnum.search(val):
                # try google calculator if not a number
                val = self.google.calculator(val)
                val = self.numsep.sub(r'\1\2', val)
                val = self.sep.split(val)[1]
                val = val.split()[0]
            val = float(val)

            # sanity check value
            if val < self.min:
                val = self.min
            elif val > self.max:
                val = self.max

            # create bar
            pos = int(round((self.size - 1) * ((val - self.min) / self.range)))
            bar = list(self.bar)
            bar[pos] = 'o'
            bar = ''.join(bar)
            bar = '|' + bar + '|'
            response = '%s: %s' % (self.title, bar)
            return response
                
        except Exception, e:
            log.warn('error in %s: %s' % (self.__module__, e))
            log.exception(e)
            return '%s: %s' % (nick, self.error)
Example #5
0
class Main(Module):
    pattern = re.compile('^\s*google\s+(.*?)\s*$')
    require_addressing = True
    help = "google <query> - i'm feeling lucky"

    def __init__(self, *args, **kwargs):
        self.google = Google()

    def response(self, nick, args, kwargs):
        try:
            query = args[0]
            return '%s: %s' % (nick, self.google.lucky(query))
        except Exception, e:
            log.warn('error in %s: %s' % (self.__module__, e))
            log.exception(e)
            return '%s: Not so lucky today..' % nick
Example #6
0
class Main(Module):

    pattern = re.compile(r'^\s*sing\s+(.+?)\s*$', re.I)
    help = 'sing <song/artist>'

    baseurl = u'http://lyrics.wikia.com/'
    searchurl = urljoin(baseurl, u'/Special:Search')

    _br = r'\s*<br\s*/?\s*>\s*'
    _line_break = re.compile(_br, re.I)
    _verse_break = re.compile(_br * 2, re.I)

    def __init__(self, *args, **kwargs):
        self.google = Google()
        super(Main, self).__init__()

    def normalize(self, lyrics):
        verses = self._verse_break.split(lyrics)
        verses = [self._line_break.sub(' / ', verse) for verse in verses]
        verses = [stripHTML(verse) for verse in verses]
        return '\n'.join(verses).strip()

    def response(self, nick, args, kwargs):
        try:
            try:
                url = self.google.lucky(u'site:lyrics.wikia.com ' + args[0])
            except NonRedirectResponse:
                opts = {'search': args[0], 'ns0': 1}
                soup = getsoup(self.searchurl, referer=self.baseurl, opts=opts)
                url = urljoin(self.baseurl, soup.li.a['href'])
            soup = getsoup(url, referer=self.baseurl)
            title = self.render(soup.title).split(' - LyricWiki')[0]
            title = title.replace(':', ' - ')
            title = title.replace('_', ' ')
            lyrics = soup.find('div', 'lyricbox')
            for spam in lyrics('div', 'rtMatcher'):
                spam.extract()
            lyrics = self.render(lyrics)
            lyrics = self.normalize(lyrics)
            if not lyrics or lyrics == 'None':
                raise ValueError('no results')
            return u'%s:\n%s' % (title, lyrics)
        except Exception, error:
            log.warn('error in module %s' % self.__module__)
            log.exception(error)
            return u'%s: %s' % (nick, "Couldn't find them, they must suck")
Example #7
0
File: calc.py Project: gipi/Richie
class Main(Module):
    pattern = re.compile('^\s*calc\s+(.+)', re.I)
    require_addressing = True
    help = 'calc <expression> - pass expression to google calculator'

    def __init__(self, madcow=None):
        self.google = Google()

    def response(self, nick, args, kwargs):
        try:
            query = args[0]
            response = self.google.calculator(query)
            return '%s: %s' % (nick, response)
        except Exception, e:
            log.warn('error in %s: %s' % (self.__module__, e))
            log.exception(e)
            return '%s: No results (bad syntax?)' % nick
Example #8
0
File: calc.py Project: gipi/Richie
class Main(Module):
    pattern = re.compile('^\s*calc\s+(.+)', re.I)
    require_addressing = True
    help = 'calc <expression> - pass expression to google calculator'

    def __init__(self, madcow=None):
        self.google = Google()

    def response(self, nick, args, kwargs):
        try:
            query = args[0]
            response = self.google.calculator(query)
            return '%s: %s' % (nick, response)
        except Exception, e:
            log.warn('error in %s: %s' % (self.__module__, e))
            log.exception(e)
            return '%s: No results (bad syntax?)' % nick
Example #9
0
class Main(Module):
    pattern = re.compile(r'^\s*spell(?:\s*check)?\s+(.+?)\s*$', re.I)
    help = 'spellcheck <word> - use google to spellcheck'

    def __init__(self, madcow=None):
        self.google = Google()

    def response(self, nick, args, kwargs):
        try:
            query = args[0]
            corrected = self.google.spellcheck(query)
            if query.lower() == corrected.lower():
                result = 'spelled correctly'
            else:
                result = corrected
            return '%s: %s' % (nick, result)
        except Exception, e:
            log.warn('error in %s: %s' % (self.__module__, e))
            log.exception(e)
            return '%s: %s' % (nick, self.error)
Example #10
0
class Main(Module):
    pattern = re.compile(r'^\s*spell(?:\s*check)?\s+(.+?)\s*$', re.I)
    help = 'spellcheck <word> - use google to spellcheck'

    def __init__(self, madcow=None):
        self.google = Google()

    def response(self, nick, args, kwargs):
        try:
            query = args[0]
            corrected = self.google.spellcheck(query)
            if query.lower() == corrected.lower():
                result = 'spelled correctly'
            else:
                result = corrected
            return '%s: %s' % (nick, result)
        except Exception, e:
            log.warn('error in %s: %s' % (self.__module__, e))
            log.exception(e)
            return '%s: %s' % (nick, self.error)
Example #11
0
class WorldClock(Module):

    pattern = re.compile(r'^\s*(?:clock|time)(?:\s*[:-]\s*|\s+)(.+?)\s*$', re.I)
    help = u'time <location> - ask google what time it is somewhere'
    in_re = re.compile(r'^\s*in\s+', re.I)

    def __init__(self, madcow=None):
        self.madcow = madcow
        self.google = Google()

    def response(self, nick, args, kwargs):
        try:
            query = args[0]
            query = self.in_re.sub('', query)
            result = self.google.clock(query)
            if result:
                return u'%s: %s' % (nick, result)
            else:
                return u"%s: They don't do the whole time thing in \"%s\"" % (
                        nick, query)
        except Exception, error:
            log.warn('error in module %s' % self.__module__)
            log.exception(error)
            return u'%s: %s' % (nick, error)
Example #12
0
 def __init__(self, *args, **kwargs):
     self.google = Google()
     super(Main, self).__init__()
Example #13
0
 def __init__(self, madcow=None):
     self.madcow = madcow
     self.google = Google()
Example #14
0
File: calc.py Project: gipi/Richie
 def __init__(self, madcow=None):
     self.google = Google()
Example #15
0
 def __init__(self, *args, **kwargs):
     self.google = Google()
Example #16
0
 def __init__(self, *args, **kwargs):
     self.google = Google()