Ejemplo n.º 1
0
    def ipinfo(self):
        web = Web()
        uri = 'http://whatismyipaddress.com/ip/'
        try:
            answer = web.html(web.get(uri + self.args[0]))

            if answer:
                th = answer.findAll('th')
                td = answer.findAll('td')

                infos = []
                for x in range(len(td)):
                    key = th[x].string.lower().strip()
                    value = re.sub(
                        '\([^()]+\)', '',
                        re.sub('<[^<>]*>', '',
                               str(td[x])).strip('\n').replace('&nbsp;',
                                                               '').strip())
                    if not value.startswith('None') and len(value):
                        infos.append("%s %s" % (key, value))
            else:
                return False
        except:
            return False

        if len(infos):
            self.parent.conn.privmsg(self.channel, ', '.join(infos))
Ejemplo n.º 2
0
 def chuck(self):
     web = Web()
     try:
         answer = web.json(web.get("http://api.icndb.com/jokes/random"))
         self.parent.conn.privmsg(self.channel, answer['value']['joke'])
     except:
         return False
Ejemplo n.º 3
0
    def imdb(self):
        if len(self.args) < 1:
            return False
        else:
            movie = ' '.join(self.args[0:])

        try:
            web = Web()
            movie = movie.replace(' ', '+')
            url = "http://www.imdbapi.com/?t=" + movie
            response = web.json(web.get(url))
            if not isinstance(response, types.NoneType):
                if 'Error' in response:
                    return False
                else:
                    infos = {
                        'title': response['Title'],
                        'year': response['Year'][:4],
                        'genre': response['Genre'],
                        'rating': response['imdbRating'],
                        'url': 'http://imdb.com/title/%s' % response['imdbID'],
                    }

                    result = "%(title)s, genre: %(genre)s, year: %(year)s, rating: %(rating)s, url: %(url)s" % infos
                    self.parent.conn.privmsg(self.channel, result)
        except:
            return False
Ejemplo n.º 4
0
    def weather(self):
        if len(self.args) < 1:
            place = 'sao paulo sp brazil'
        else:
            place = ' '.join(self.args[0:])

        if 'inferno' in place:
            date = datetime.datetime.now().strftime("BR at %H:00 %p BRT")
            self.parent.conn.privmsg(self.channel, "Conditions for %s, %s: Fair, 666 °C, high: 999 °C, low: 66 °C" % (place.capitalize(), date))

        try:
            web = Web()
            url = 'http://query.yahooapis.com/v1/public/yql'
            query = web.encode({'q': 'select item from weather.forecast where woeid in (select woeid from geo.places where text="%s") and u="c"' % place})
            response = web.json(web.get("%s?%s&format=json&callback=" % (url, query)))
            try:
                data = response["query"]["results"]["channel"][0]['item']
            except:
                data = response["query"]["results"]["channel"]['item']
            infos = {
                'place': data['title'],
                'temperature': data['condition']['temp'],
                'condition': data['condition']['text'],
                'high': data['forecast'][0]['high'],
                'low': data['forecast'][0]['low'],
                }

            result = "%(place)s: %(condition)s, %(temperature)s °C, high: %(high)s °C, low: %(low)s °C" % infos
            self.parent.conn.privmsg(self.channel, result)
        except:
            return False
Ejemplo n.º 5
0
    def imdb(self):
        if len(self.args) < 1:
            return False
        else:
            movie = ' '.join(self.args[0:])

        try:
            web = Web()
            movie = movie.replace(' ', '+')
            url = "http://www.imdbapi.com/?t=" + movie
            response = web.json(web.get(url))
            if not isinstance(response, types.NoneType):
                if 'Error' in response:
                    return False
                else:
                    infos = {
                        'title': response['Title'],
                        'year': response['Year'][:4],
                        'genre': response['Genre'],
                        'rating': response['imdbRating'],
                        'url': 'http://imdb.com/title/%s' % response['imdbID'],
                    }

                    result = "%(title)s, genre: %(genre)s, year: %(year)s, rating: %(rating)s, url: %(url)s" % infos
                    self.parent.conn.privmsg(self.channel, result)
        except:
            return False
Ejemplo n.º 6
0
 def chuck(self):
     web = Web()
     try:
         answer = web.json(web.get("http://api.icndb.com/jokes/random"))
         self.parent.conn.privmsg(self.channel, answer['value']['joke'])
     except:
         return False
Ejemplo n.º 7
0
 def btc(self):
     web = Web()
     try:
         answer = web.html(web.get('http://bitcoinexchangerate.org/c/USD/1'))
         pattern = re.compile('([0-9.]+)')
         result = re.findall(pattern, str(answer.title.string))[0]
         self.parent.conn.privmsg(self.channel, "%s USD / BTC" % round(float(result), 2))
     except:
         return False
Ejemplo n.º 8
0
    def cotacao(self):
        url = 'http://economia.uol.com.br/cotacoes'
        web = Web()
        response = web.html(web.get(url))
        result = []
        infos = {}

        if len(self.args) < 1:
            exchange = None
        else:
            exchange = self.args[0]

        regex = {
            'dolar turismo':
            [r'(d.lar\stur.)\n.ompra\s+(?P<compra>.+)\n.enda\s+(?P<venda>.+)'],
            'dolar comercial': [
                r'(d.lar\scom.)\n.ompra\s+(?P<compra>.+)\n.enda\s+(?P<venda>.+)',
                r'(d.lar\s.omercial)\n(?P<compra>.+)\n(?P<venda>.+)'
            ],
            'euro': [
                r'(euro)\n.ompra\s+(?P<compra>.+)\n.enda\s+(?P<venda>.+)',
                r'(euro)\n(?P<compra>.+)\n(?P<venda>.+)'
            ],
            'libra': [
                r'(libra)\n.ompra\s+(?P<compra>.+)\n.enda\s+(?P<venda>.+)',
                r'(libra)\n(?P<compra>.+)\n(?P<venda>.+)'
            ],
        }

        if response:
            try:
                for k, v in regex.iteritems():
                    for l in v:
                        r = re.compile(l, re.I).search(response.text)
                        if not isinstance(r, types.NoneType):
                            if k not in infos:
                                infos[k] = "compra = %s, venda = %s" % (
                                    r.group(2).replace(',', '.'),
                                    r.group(3).replace(',', '.'))

                if exchange:
                    for k, v in infos.iteritems():
                        if exchange in k:
                            result.append("%s: %s, " % (k, v))
                else:
                    for k, v in infos.iteritems():
                        result.append("%s: %s, " % (k, v))

                if result:
                    result.append('fonte: %s' % url.split('/')[2])
                    self.parent.conn.privmsg(
                        self.channel, '%s, %s' % (self.nick, ''.join(result)))
            except:
                return False
Ejemplo n.º 9
0
 def sl(self):
     user = '******'
     number = 60
     web = Web()
     try:
         answer = web.json(web.get("http://search.twitter.com/search.json?q=@%s&rpp=%s&include_entities=true&result_type=recent" % (user, number)))
         pattern = re.compile('(\'media_url\':\s?u\')(http://[^\s]+)\'')
         result = []
         [ result.append(line[1]) for line in re.findall(pattern, str(answer)) if not line[1] in result ]
         self.parent.conn.privmsg(self.channel, random.choice(result))
     except:
         return False
Ejemplo n.º 10
0
 def transito(self):
     web = Web()
     answer = web.html(web.get('http://cetsp1.cetsp.com.br/monitransmapa/agora/'))
     if answer:
         dados = {
             'hora': answer.find('div', id="hora").findAll(text=True)[0],
             'lentidao': answer.find('div', id="lentidao").findAll(text=True)[0],
         }
         result = "%(lentidao)s km de transito, atualizado as %(hora)s" % dados
         self.parent.conn.privmsg(self.channel, result)
     else:
         return False
Ejemplo n.º 11
0
    def transito(self):
        web = Web()
        answer = web.html(web.get('http://cetsp1.cetsp.com.br/monitransmapa/agora/'))
        if answer:
            dados = {
                'hora': answer.find('div', id="hora").findAll(text=True)[0],
                'lentidao': answer.find('div', id="lentidao").findAll(text=True)[0],
            }
            result = "%(lentidao)s km de transito em SP, atualizado as %(hora)s" % dados
            self.parent.conn.privmsg(self.channel, result)
            self.parent.conn.privmsg(self.channel, '%s' % ('Quer o transito de BH? www.maplink.com.br/MG/belo_horizonte/TransitoAgora '))

        else:
            return False
Ejemplo n.º 12
0
    def dic(self):
	if len(self.args) < 1:
		self.parent.conn.privmsg(self.channel, '%s' % ('Digite a palavra que gostaria de procurar'))
	else:
		web = Web()
		answer = web.html(web.get('http://michaelis.uol.com.br/moderno/portugues/index.php?lingua=portugues-portugues&palavra='+self.args[0]))
		if answer:
			dados = {
				'significado': answer.find('div', id="descricao").findAll(text=True)[0],
			}
			result = "Significado: %(significado)s " % dados
			self.parent.conn.privmsg(self.channel, result)
		else:
		    return False
Ejemplo n.º 13
0
    def dollar(self):
        url = 'http://www4.bcb.gov.br/feed/taxas.ashx'
        web = Web()
        result = web.xml(web.get(url))

        if result:

            for element in result.getElementsByTagName("item"):
                title = self.get_text(element.getElementsByTagName("title")[0].childNodes)
                description = self.get_text(element.getElementsByTagName("description")[0].childNodes)
                if str(title).endswith('EUA'):
                    data = "%s %s" % (title, ' '.join(web.html(description).findAll('div', id='value', text=True)))

            data += ', fonte: www.bcb.gov.br'
            self.parent.conn.privmsg(self.channel, '%s, %s' % (self.nick, data.lower().replace('&agrave;', 'à')))
Ejemplo n.º 14
0
    def dollar(self):
        url = "http://www4.bcb.gov.br/feed/taxas.ashx"
        web = Web()
        result = web.xml(web.get(url))

        if result:

            for element in result.getElementsByTagName("item"):
                title = self.get_text(element.getElementsByTagName("title")[0].childNodes)
                description = self.get_text(element.getElementsByTagName("description")[0].childNodes)
                if str(title).endswith("EUA"):
                    data = "%s %s" % (title, " ".join(web.html(description).findAll("div", id="value", text=True)))

            data += ", fonte: www.bcb.gov.br"
            self.parent.conn.privmsg(self.channel, "%s, %s" % (self.nick, data.lower().replace("&agrave;", "à")))
Ejemplo n.º 15
0
def ipinfo(args):
    try:
        web = Web()
        uri = 'http://whatismyipaddress.com/ip/'
        answer = web.html(web.get(uri + args))
        return answer

        th = answer.findAll('th')
        td = answer.findAll('td')

        infos = []
        for x in range(len(td)):
            key = th[x].string.lower().strip()
            value = re.sub('\([^()]+\)', '', re.sub('<[^<>]*>', '', str(td[x])).strip('\n').replace('&nbsp;', '').strip())
            if not value.startswith('None') and len(value):
                infos.append("%s %s" % (key, value))
        return ', '.join(infos)
    except Exception, e:
        return repr(e)
Ejemplo n.º 16
0
    def transito(self):
        web = Web()
        answer = web.html(
            web.get('http://cetsp1.cetsp.com.br/monitransmapa/agora/'))
        if answer:
            dados = {
                'hora':
                answer.find('div', id="hora").findAll(text=True)[0],
                'lentidao':
                answer.find('div', id="lentidao").findAll(text=True)[0],
            }
            result = "%(lentidao)s km de transito em SP, atualizado as %(hora)s" % dados
            self.parent.conn.privmsg(self.channel, result)
            self.parent.conn.privmsg(
                self.channel, '%s' %
                ('Quer o transito de BH? www.maplink.com.br/MG/belo_horizonte/TransitoAgora '
                 ))

        else:
            return False
Ejemplo n.º 17
0
    def ipinfo(self):
        web = Web()
        uri = 'http://whatismyipaddress.com/ip/'
        answer = web.html(web.get(uri + self.args[0]))

        if answer:
            th = answer.findAll('th')
            td = answer.findAll('td')

            infos = []
            for x in range(len(td)):
                key = th[x].string.lower().strip()
                value = str(html.fromstring(str(td[x]).replace('\n', '')).text).strip()
                if not value.startswith('None'):
                    infos.append("%s %s" % (key, value))
        else:
            return False

        if len(infos):
            self.parent.conn.privmsg(self.channel, ', '.join(infos))
Ejemplo n.º 18
0
    def ipinfo(self):
        web = Web()
        uri = 'http://ip.nixdns.com.br/plain/'
        answer = web.html(web.get(uri + self.args[0]))

        if answer:
            th = answer.findAll('th')
            td = answer.findAll('td')

            infos = []
            for x in range(len(td)):
                key = th[x].string.lower().strip()
                value = str(html.fromstring(str(td[x]).replace('\n', '')).text).strip()
                if not value.startswith('None'):
                    infos.append("%s %s" % (key, value))
        else:
            return False

        if len(infos):
            self.parent.conn.privmsg(self.channel, ', '.join(infos))
Ejemplo n.º 19
0
 def dic(self):
     if len(self.args) < 1:
         self.parent.conn.privmsg(
             self.channel,
             '%s' % ('Digite a palavra que gostaria de procurar'))
     else:
         web = Web()
         answer = web.html(
             web.get(
                 'http://michaelis.uol.com.br/moderno/portugues/index.php?lingua=portugues-portugues&palavra='
                 + self.args[0]))
         if answer:
             dados = {
                 'significado':
                 answer.find('div', id="descricao").findAll(text=True)[0],
             }
             result = "Significado: %(significado)s " % dados
             self.parent.conn.privmsg(self.channel, result)
         else:
             return False
Ejemplo n.º 20
0
    def weather(self):
        if len(self.args) < 1:
            place = 'belo horizonte mg brazil'
        else:
            place = ' '.join(self.args[0:])

        if 'inferno' in place:
            date = datetime.datetime.now().strftime("BR at %H:00 %p BRT")
            self.parent.conn.privmsg(
                self.channel,
                "Conditions for %s, %s: Fair, 666 °C, high: 999 °C, low: 66 °C"
                % (place.capitalize(), date))

        try:
            web = Web()
            url = 'http://query.yahooapis.com/v1/public/yql'
            query = web.encode({
                'q':
                'select item from weather.forecast where woeid in (select woeid from geo.places where text="%s") and u="c"'
                % place
            })
            response = web.json(
                web.get("%s?%s&format=json&callback=" % (url, query)))
            try:
                data = response["query"]["results"]["channel"][0]['item']
            except:
                data = response["query"]["results"]["channel"]['item']
            infos = {
                'place': data['title'],
                'temperature': data['condition']['temp'],
                'condition': data['condition']['text'],
                'high': data['forecast'][0]['high'],
                'low': data['forecast'][0]['low'],
            }

            result = "%(place)s: %(condition)s, %(temperature)s °C, high: %(high)s °C, low: %(low)s °C" % infos
            self.parent.conn.privmsg(self.channel, result)
        except:
            return False
Ejemplo n.º 21
0
def ipinfo(args):
    try:
        web = Web()
        uri = 'http://whatismyipaddress.com/ip/'
        answer = web.html(web.get(uri + args))
        return answer

        th = answer.findAll('th')
        td = answer.findAll('td')

        infos = []
        for x in range(len(td)):
            key = th[x].string.lower().strip()
            value = re.sub(
                '\([^()]+\)', '',
                re.sub('<[^<>]*>', '',
                       str(td[x])).strip('\n').replace('&nbsp;', '').strip())
            if not value.startswith('None') and len(value):
                infos.append("%s %s" % (key, value))
        return ', '.join(infos)
    except Exception, e:
        return repr(e)
Ejemplo n.º 22
0
    def ipinfo(self):
        web = Web()
        uri = 'http://whatismyipaddress.com/ip/'
        try:
            answer = web.html(web.get(uri + self.args[0]))

            if answer:
                th = answer.findAll('th')
                td = answer.findAll('td')

                infos = []
                for x in range(len(td)):
                    key = th[x].string.lower().strip()
                    value = re.sub('\([^()]+\)', '', re.sub('<[^<>]*>', '', str(td[x])).strip('\n').replace('&nbsp;', '').strip())
                    if not value.startswith('None') and len(value):
                        infos.append("%s %s" % (key, value))
            else:
                return False
        except:
            return False

        if len(infos):
            self.parent.conn.privmsg(self.channel, ', '.join(infos))