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'[Film] Erreur 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'[Film] Titre: ' + data['Title'] + \ u' | Director: ' + data['Director'] + \ u' | Année: ' + data['Year'] + \ u' | Valoration: ' + data['imdbRating'] + ' i ' + data['imdbVotes'] + ' personnes ont voté.' + \ u' | Genre: ' + data['Genre'] + \ u' | Prix: ' + data['Awards'] + \ u' | Durée: ' + data['Runtime'] + \ ' | Link a IMDB: http://imdb.com/title/' + data['imdbID'] elif bot.config.lang == 'es': message = u'[Película] Título: ' + data['Title'] + \ u' | Director: ' + data['Director'] + \ u' | Año: ' + data['Year'] + \ u' | Valoración: ' + data['imdbRating'] + ' y ' + data['imdbVotes'] + ' personas han votado.' + \ u' | Género: ' + data['Genre'] + \ u' | Premios: ' + data['Awards'] + \ u' | Duración: ' + data['Runtime'] + \ ' | Link a IMDB: http://imdb.com/title/' + data['imdbID'] else: message = '[MOVIE] Title: ' + data['Title'] + \ ' | Director: ' + data['Director'] + \ ' | Year: ' + data['Year'] + \ ' | Rating: ' + data['imdbRating'] + ' and ' + data['imdbVotes'] + ' people have voted.' + \ ' | Genre: ' + data['Genre'] + \ ' | Awards: ' + data['Awards'] + \ ' | Runtime: ' + data['Runtime'] + \ ' | IMDB Link: http://imdb.com/title/' + data['imdbID'] bot.say(message)
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
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, 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 "spam spam" not 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')