def _np(self, cmd=None, args=None): if args in self.genres: json_results = \ urllib.urlopen( 'http://radioreddit.com/api/{0}/status.json'.format(args) ) elif not args: json_results = \ urllib.urlopen('http://radioreddit.com/api/status.json') results = json.loads(json_results.read())['songs']['song'][0] url = str(results['reddit_url']) result = \ chr(2) + results['title'] + chr(2) \ + ' -- ' + \ results['artist'] \ + ' ' + \ '(Redditor: {0})'.format(results['redditor']) \ + ' ' + \ bitly.shorten(url)['url'] if args: now_playing = \ 'Now playing on the {0} stream: '.format(args[-1]) + result self.reply(now_playing) else: now_playing = 'Now playing on Radio Reddit: ' + result self.reply(now_playing)
def _search(self, cmd=None, args=None): query = args url = urlparse.urlunsplit( ( 'http', 'ajax.googleapis.com', '/ajax/services/search/web', 'v=1.0&q={0}'.format(query), None, ) ) results = urllib.urlopen(url) results = json.loads(results.read())['responseData']['results'] if not results: error = 'Request error: no results' self.reply(error) self.logger.warning(error) else: url = urllib.unquote(results[0]['url']) url = bitly.shorten(url)['url'] title = unescape(results[0]['titleNoFormatting']) lucky = title + ' -- ' + url self.reply(lucky)
def _search(self, cmd, args): query = args if not args: return url = urlparse.urlunsplit( ( 'http', 'gdata.youtube.com', '/feeds/api/videos', 'v=2&alt=jsonc&q={0}'.format(query), '' ) ) results = urllib.urlopen(url) results = json.loads(results.read())['data']['items'][0] if not results: self.reply('Request error: no results') else: url = 'http://www.youtube.com/watch?v={0}'.format(results['id']) url = bitly.shorten(url)['url'] title = results['title'] desc = results['description'][:156] lucky = title + ' -- ' + desc + ' -- ' + url self.reply(lucky)
def _shorten(self, cmd, args): print(cmd) url = cmd if not url or ('bit.ly' in url) or ('.' not in url): print('shit shit') return url = bitly.shorten(url)['url'] if not len(self.msgs) >= MIN_LEN: return self.reply(url)
def _send_response(self, cmd=None, args=None): query = args query = urllib.quote(query) url = 'http://www.imdbapi.com/?t={0}'.format(query) result = json.load(urllib.urlopen(url)) if result['Response'] == 'True': film_id = result['ID'] film_url = 'http://www.imdb.com/title/' + film_id film_url = bitly.shorten(film_url)['url'] title = result['Title'] desc = result['Plot'] self.bot.msg(self.sender, title + ' -- ' + desc + ' -- ' + film_url)
def _send_response(self, cmd=None, args=None): query = args query = urllib.quote(query) url = 'http://www.imdbapi.com/?t={0}'.format(query) result = json.load(urllib.urlopen(url)) if result['Response'] == 'True': film_id = result['ID'] film_url = 'http://www.imdb.com/title/' + film_id film_url = bitly.shorten(film_url)['url'] title = result['Title'] desc = result['Plot'] self.bot.msg( self.sender, title + ' -- ' + desc + ' -- ' + film_url )
def _search(self, cmd=None, args=None): query = args url = urlparse.urlunsplit( ("http", "ajax.googleapis.com", "/ajax/services/search/web", "v=1.0&q={0}".format(query), None) ) results = urllib.urlopen(url) results = json.loads(results.read())["responseData"]["results"] if not results: error = "Request error: no results" self.reply(error) self.logger.warning(error) else: url = urllib.unquote(results[0]["url"]) url = bitly.shorten(url)["url"] title = unescape(results[0]["titleNoFormatting"]) lucky = title + " -- " + url self.reply(lucky)
def _search(self, cmd, args): query = args if not args: return url = urlparse.urlunsplit( ('http', 'gdata.youtube.com', '/feeds/api/videos', 'v=2&alt=jsonc&q={0}'.format(query), '')) results = urllib.urlopen(url) results = json.loads(results.read())['data']['items'][0] if not results: self.reply('Request error: no results') else: url = 'http://www.youtube.com/watch?v={0}'.format(results['id']) url = bitly.shorten(url)['url'] title = results['title'] desc = results['description'][:156] lucky = title + ' -- ' + desc + ' -- ' + url self.reply(lucky)