コード例 #1
0
    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)
コード例 #2
0
ファイル: google.py プロジェクト: ethinx/kaa
 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) 
コード例 #3
0
ファイル: radioreddit.py プロジェクト: ethinx/kaa
 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)
コード例 #4
0
ファイル: youtube.py プロジェクト: ethinx/kaa
 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)
コード例 #5
0
ファイル: bitly.py プロジェクト: ethinx/kaa
 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)
コード例 #6
0
ファイル: imdb.py プロジェクト: ethinx/kaa
    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)
コード例 #7
0
ファイル: imdb.py プロジェクト: ethinx/kaa
 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
                     )
コード例 #8
0
ファイル: google.py プロジェクト: ethinx/kaa
    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)
コード例 #9
0
ファイル: youtube.py プロジェクト: ethinx/kaa
    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)