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
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
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
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
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
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
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