コード例 #1
0
def ud_search(bot, trigger):
    query = trigger.group(2).strip()
    
    url = 'http://api.urbandictionary.com/v0/define?term=%s' %(query.encode('utf-8'))
    #bot.say(url)
    try:
      response = web.get_urllib_object(url, 20)
    except UnicodeError:
      bot.say('[UrbanDictionary] ENGLISH M**********R, DO YOU SPEAK IT?')
      return
    else:
      data = json.loads(response.read())
      #bot.say(str(data))
    try:
      definition = data['list'][0]['definition'].replace('\n', ' ')
    except KeyError:
      bot.say('[UrbanDictionary] Something went wrong bruh')
    except IndexError:
      bot.say('[UrbanDictionary] No results, do you even spell bruh?')
    else:
      thumbsup = color(str(data['list'][0]['thumbs_up'])+'+', u'03')
      thumbsdown = color(str(data['list'][0]['thumbs_down'])+'-', u'04')
      permalink = data['list'][0]['permalink']
      length = len(thumbsup)+len(thumbsdown)+len(permalink)+35
      ellipsies = ''
      if (len(definition)+length) > 445:
        ellipsies = '...'
      udoutput = "[UrbanDictionary] %s; %.*s%s | %s >> %s %s" % (query, 445-length, definition, ellipsies, permalink, thumbsup, thumbsdown)
      if not "spam spam" in udoutput:
          bot.say(udoutput)
      else:
          bot.say('[UrbanDictionary] Negative ghostrider')
コード例 #2
0
ファイル: movie.py プロジェクト: pavelwen/willie
def movie(willie, trigger):
    """
    Returns some information about a movie, like Title, Year, Rating, Genre and IMDB Link.
    """
    if not trigger.group(2):
        return
    word = trigger.group(2).rstrip()
    word = word.replace(" ", "+")
    uri = "http://www.imdbapi.com/?t=" + word
    u = web.get_urllib_object(uri, 30)
    data = json.load(u)  # data is a Dict containing all the information we need
    u.close()
    if data["Response"] == "False":
        if "Error" in data:
            message = "[MOVIE] %s" % data["Error"]
        else:
            willie.debug("movie", "Got an error from the imdb api, search phrase was %s" % word, "warning")
            willie.debug("movie", str(data), "warning")
            message = "[MOVIE] Got an error from imdbapi"
    else:
        message = (
            "[MOVIE] Title: "
            + data["Title"]
            + " | Year: "
            + data["Year"]
            + " | Rating: "
            + data["imdbRating"]
            + " | Genre: "
            + data["Genre"]
            + " | IMDB Link: http://imdb.com/title/"
            + data["imdbID"]
        )
    willie.say(message)
コード例 #3
0
ファイル: movie.py プロジェクト: antiman/willie
def movie(bot, trigger):
    """
    Returns some information about a movie, like Title, Year, Rating, Genre and IMDB Link.
    """
    if not trigger.group(2):
        return
    word = trigger.group(2).rstrip()
    word = word.replace(" ", "+")
    uri = "http://www.imdbapi.com/?t=" + word
    u = web.get_urllib_object(uri, 30)
    data = json.loads(u.read().decode('utf8'))  # data is a Dict containing all the information we need
    u.close()
    if data['Response'] == 'False':
        if 'Error' in data:
            message = '[MOVIE] %s' % data['Error']
        else:
            bot.debug(__file__, 'Got an error from the imdb api, search phrase was %s' % word, 'warning')
            bot.debug(__file__, str(data), 'warning')
            message = '[MOVIE] Got an error from imdbapi'
    else:
        message = '[MOVIE] Title: ' + data['Title'] + \
                  ' | Year: ' + data['Year'] + \
                  ' | Rating: ' + data['imdbRating'] + \
                  ' | Genre: ' + data['Genre'] + \
                  ' | IMDB Link: http://imdb.com/title/' + data['imdbID']
    bot.say(message)
コード例 #4
0
ファイル: movie.py プロジェクト: CatmanIX/FlutterBitch
def movie(willie, trigger):
    """
    Returns some information about a movie, like Title, Year, Rating, Genre and IMDB Link.
    """
    if not trigger.group(2):
        return
    word = trigger.group(2).rstrip()
    word = word.replace(" ", "+")
    uri = "http://www.imdbapi.com/?t=" + word
    u = web.get_urllib_object(uri, 30)
    data = json.load(u)  #data is a Dict containing all the information we need
    u.close()
    if data['Response'] == 'False':
        if 'Error' in data:
            message = '[MOVIE] %s' % data['Error']
        else:
            willie.debug(
                'movie',
                'Got an error from the imdb api, search phrase was %s' % word,
                'warning')
            willie.debug('movie', str(data), 'warning')
            message = '[MOVIE] Got an error from imdbapi'
    else:
        message = '[MOVIE] Title: ' +data['Title']+ \
                  ' | Year: ' +data['Year']+ \
                  ' | Rating: ' +data['imdbRating']+ \
                  ' | Genre: ' +data['Genre']+ \
                  ' | IMDB Link: http://imdb.com/title/' + data['imdbID']
    willie.say(message)
コード例 #5
0
ファイル: movie.py プロジェクト: ElGatoSaez/Granota
def movie(bot, trigger):
    if not trigger.group(2):
        return
    word = trigger.group(2).rstrip()
    word = word.replace(" ", "+")
    uri = "http://www.omdbapi.com/?t=" + word
    u = web.get_urllib_object(uri, 30)
    data = json.load(u)  # data is a Dict containing all the information we need
    u.close()
    if data['Response'] == 'False':
        if 'Error' in data:
            message = '[MOVIE] %s' % data['Error']
        else:
            bot.debug(__file__, 'Got an error from the imdb api, search phrase was %s' % word, 'warning')
            bot.debug(__file__, str(data), 'warning')
            if bot.config.lang == 'ca':
                message = u'[Pel·lícula] Error de l\'API d\'imdb'
            elif bot.config.lang == 'es':
                message = u'[Película] Error de la API de imdb'
            else:
                message = '[Movie] Error from the imdb API'
    else:
        link = '\x0302http://imdb.com/title/' + data['imdbID'] + '\x0F'
        ratingraw = data['imdbRating']
        if ratingraw < 5:
            rating = '\x0304' + ratingraw + '\x0F'
        elif ratingraw >= 5 and ratingraw < 7:
            rating = '\x0308' + ratingraw + '\x0F'
        else:
            rating = '\x0303' + ratingraw + '\x0F'
        if bot.config.lang == 'ca':
            message = '\x02\x0301,08IMDB\x0F\x02 - ' + data['Title'] + '\x0F' +  \
                    u' | Director: ' + data['Director'] + \
                    u' | Any: ' + data['Year'] + \
                    u' | Valoració: ' + rating + ' i han votat ' + data['imdbVotes'] + ' persones.' + \
                    u' | Gènere: ' + data['Genre'] + \
                    u' | Premis: ' + data['Awards'] + \
                    u' | Duració: ' + data['Runtime'] + \
                    ' | Link a IMDB: ' + link
        elif bot.config.lang == 'es':
            message = '\x02\x0301,08IMDB\x0F\x02 - ' + data['Title'] + '\x0F' +  \
                    u' | Director: ' + data['Director'] + \
                    u' | Año: ' + data['Year'] + \
                    u' | Valoración: ' + rating + ' y han votado ' + data['imdbVotes'] + ' personas.' + \
                    u' | Género: ' + data['Genre'] + \
                    u' | Premios: ' + data['Awards'] + \
                    u' | Duración: ' + data['Runtime'] + \
                    ' | Link a IMDB: ' + link
        else:
            message = '\x02\x0301,08IMDB\x0F\x02 - ' + data['Title'] + '\x0F' + \
                      ' | Director: ' + data['Director'] + \
                      ' | Year: ' + data['Year'] + \
                      ' | Rating: ' + rating + ' and ' + data['imdbVotes'] + ' people have voted.' + \
                      ' | Genre: ' + data['Genre'] + \
                      ' | Awards: ' + data['Awards'] + \
                      ' | Runtime: ' + data['Runtime'] + \
                      ' | IMDB Link: ' + link
    bot.say(message)
コード例 #6
0
def follow_redirects(url):
    """
    Follow HTTP 3xx redirects, and return the actual URL. Return None if
    there's a problem.
    """
    try:
        connection = web.get_urllib_object(url, 60)
        url = connection.geturl() or url
        connection.close()
    except:
        return None
    return url
コード例 #7
0
def ud_search(bot, trigger):
    query = trigger.group(2).strip()

    url = 'http://api.urbandictionary.com/v0/define?term=%s' % (
        query.encode('utf-8'))
    #bot.say(url)
    try:
        response = web.get_urllib_object(url, 20)
    except UnicodeError:
        bot.say('[UrbanDictionary] ENGLISH M**********R, DO YOU SPEAK IT?')
        return
    else:
        data = json.loads(response.read())
        #bot.say(str(data))
    try:
        definition = data['list'][0]['definition'].replace('\n', ' ')
    except KeyError:
        bot.say('[UrbanDictionary] Something went wrong bruh')
    except IndexError:
        bot.say('[UrbanDictionary] No results, do you even spell bruh?')
    else:
        thumbsup = color(str(data['list'][0]['thumbs_up']) + '+', u'03')
        thumbsdown = color(str(data['list'][0]['thumbs_down']) + '-', u'04')
        permalink = data['list'][0]['permalink']
        length = len(thumbsup) + len(thumbsdown) + len(permalink) + 35
        ellipsies = ''
        if (len(definition) + length) > 445:
            ellipsies = '...'
        udoutput = "[UrbanDictionary] %s; %.*s%s | %s >> %s %s" % (
            query, 445 - length, definition, ellipsies, permalink, thumbsup,
            thumbsdown)
        if not "spam spam" in udoutput:
            if not trigger.sender.is_nick() and bot.privileges[trigger.sender][
                    trigger.nick] < VOICE:
                bot.notice(udoutput, recipient=trigger.nick)
            else:
                bot.say(udoutput)
        else:
            if not trigger.sender.is_nick() and bot.privileges[trigger.sender][
                    trigger.nick] < VOICE:
                bot.notice('[UrbanDictionary] Negative ghostrider',
                           recipient=trigger.nick)
            else:
                bot.say('[UrbanDictionary] Negative ghostrider')
コード例 #8
0
ファイル: movie.py プロジェクト: NeoMahler/Granota
def movie(bot, trigger):
    """
    Returns some information about a movie, like Title, Year, Rating, Genre and IMDB Link.
    """
    if not trigger.group(2):
        return
    word = trigger.group(2).rstrip()
    word = word.replace(" ", "+")
    uri = "http://www.imdbapi.com/?t=" + word
    u = web.get_urllib_object(uri, 30)
    data = json.load(u)  # data is a Dict containing all the information we need
    u.close()
    if data['Response'] == 'False':
        if 'Error' in data:
            message = '[MOVIE] %s' % data['Error']
        else:
            bot.debug(__file__, 'Got an error from the imdb api, search phrase was %s' % word, 'warning')
            bot.debug(__file__, str(data), 'warning')
            if bot.config.lang == 'ca':
                message = u'[Pel·lícula] Error de l\'API d\'imdb'
            elif bot.config.lang == 'es':
                message = u'[Película] Error de la API de imdb'
            else:
                message = '[MOVIE] Error from the imdb API'
    else:
        if bot.config.lang == 'ca':
            message = u'[Pel·lícula] Títol: ' + data['Title'] + \
                    ' | Any: ' + data['Year'] + \
                    u' | Valoració: ' + data['imdbRating'] + \
                    u' | Gènere: ' + data['Genre'] + \
                    ' | Link a IMDB: http://imdb.com/title/' + data['imdbID']
        elif bot.config.lang == 'es':
            message = u'[Película] Título: ' + data['Title'] + \
                    u' | Año: ' + data['Year'] + \
                    u' | Valoración: ' + data['imdbRating'] + \
                    u' | Género: ' + data['Genre'] + \
                    ' | Link a IMDB: http://imdb.com/title/' + data['imdbID']
        else:
            message = '[MOVIE] Title: ' + data['Title'] + \
                      ' | Year: ' + data['Year'] + \
                      ' | Rating: ' + data['imdbRating'] + \
                      ' | Genre: ' + data['Genre'] + \
                      ' | IMDB Link: http://imdb.com/title/' + data['imdbID']
    bot.say(message)
コード例 #9
0
ファイル: movie.py プロジェクト: Worldev/Granota
def movie(bot, trigger):
    if not trigger.group(2):
        return
    word = trigger.group(2).rstrip()
    word = word.replace(" ", "+")
    uri = "http://www.omdbapi.com/?t=" + word
    u = web.get_urllib_object(uri, 30)
    data = json.load(
        u)  # data is a Dict containing all the information we need
    u.close()
    if data['Response'] == 'False':
        if 'Error' in data:
            message = '[MOVIE] %s' % data['Error']
        else:
            bot.debug(
                __file__,
                'Got an error from the imdb api, search phrase was %s' % word,
                'warning')
            bot.debug(__file__, str(data), 'warning')
            if bot.config.lang == 'ca':
                message = u'[Pel·lícula] Error de l\'API d\'imdb'
            elif bot.config.lang == 'es':
                message = u'[Película] Error de la API de imdb'
            else:
                message = '[Movie] Error from the imdb API'
    else:
        link = '\x0302http://imdb.com/title/' + data['imdbID'] + '\x0F'
        ratingraw = data['imdbRating']
        if ratingraw < 5:
            rating = '\x0304' + ratingraw + '\x0F'
        elif ratingraw >= 5 and ratingraw < 7:
            rating = '\x0308' + ratingraw + '\x0F'
        else:
            rating = '\x0303' + ratingraw + '\x0F'
        if bot.config.lang == 'ca':
            message = '\x02\x0301,08IMDB\x0F\x02 - ' + data['Title'] + '\x0F' +  \
                    u' | Director: ' + data['Director'] + \
                    u' | Any: ' + data['Year'] + \
                    u' | Valoració: ' + rating + ' i han votat ' + data['imdbVotes'] + ' persones.' + \
                    u' | Gènere: ' + data['Genre'] + \
                    u' | Premis: ' + data['Awards'] + \
                    u' | Duració: ' + data['Runtime'] + \
                    ' | Link a IMDB: ' + link
        elif bot.config.lang == 'es':
            message = '\x02\x0301,08IMDB\x0F\x02 - ' + data['Title'] + '\x0F' +  \
                    u' | Director: ' + data['Director'] + \
                    u' | Año: ' + data['Year'] + \
                    u' | Valoración: ' + rating + ' y han votado ' + data['imdbVotes'] + ' personas.' + \
                    u' | Género: ' + data['Genre'] + \
                    u' | Premios: ' + data['Awards'] + \
                    u' | Duración: ' + data['Runtime'] + \
                    ' | Link a IMDB: ' + link
        else:
            message = '\x02\x0301,08IMDB\x0F\x02 - ' + data['Title'] + '\x0F' + \
                      ' | Director: ' + data['Director'] + \
                      ' | Year: ' + data['Year'] + \
                      ' | Rating: ' + rating + ' and ' + data['imdbVotes'] + ' people have voted.' + \
                      ' | Genre: ' + data['Genre'] + \
                      ' | Awards: ' + data['Awards'] + \
                      ' | Runtime: ' + data['Runtime'] + \
                      ' | IMDB Link: ' + link
    bot.say(message)
コード例 #10
0
ファイル: tiny.py プロジェクト: Ethcelon/willie
def shorten(url):
	toOpen = 'http://tinyurl.com/api-create.php?url=' + url
	html = web.get_urllib_object(toOpen,10)
	shorturl = str(html.read())
	return shorturl