コード例 #1
0
ファイル: __init__.py プロジェクト: krmnn/wall
class DropboxSearchHandler(SearchHandler):
    def __init__(self, id, box):        
        super(DropboxSearchHandler, self).__init__(id, 'Dropbox ' + box.title,
            '#0000ff')
        self.box = box
        self._api = WebAPI('https://api.dropbox.com/1',
            {'access_token': box.token})

    def search(self, query, callback):
        def cb(items):
            results = []
            def cb():
                callback(results)
            pool = Pool(items, cb)

            for item in items:
                if item.is_dir:
                    pool.finish(item)
                    continue

                def cb(link, item):
                    result = SearchResult(os.path.basename(item.path), link.url,
                        self.id)
                    results.append(result)
                    pool.finish(item)
                self._api.call('/media/dropbox' + item.path,
                    callback=partial(cb, item=item))

        self._api.call('/search/dropbox/', {'query': query, 'file_limit': '5'},
            cb)
コード例 #2
0
ファイル: __init__.py プロジェクト: NoyaInRain/wall
class YoutubeSearchHandler(SearchHandler):
    def __init__(self):
        super(YoutubeSearchHandler, self).__init__(randstr(), 'Youtube',
                                                   '#ff0000')
        # See https://developers.google.com/youtube/v3/docs/
        self._api = WebAPI('https://www.googleapis.com/youtube/v3/',
                           {'key': YOUTUBE_API_KEY})

    def search(self, query, callback):
        def cb(response):
            # At the moment we do not handle quotaExceeded errors, because it is
            # hard to test and a bit unrealistic for Wall to hit the limit.
            results = []
            for item in response.items:
                # Construct video URL (with autoplay enabled)
                video = 'https://www.youtube.com/embed/{}?autoplay=1'.format(
                    item.id.videoId)
                results.append(SearchResult(
                    item.snippet.title, video, self.id,
                    item.snippet.thumbnails.default.url))
            callback(results)

        # See https://developers.google.com/youtube/v3/docs/search
        self._api.call('search', {
            'q': query,
            'type': 'video',
            'videoEmbeddable': 'true',
            'part': 'snippet'
        }, cb)
コード例 #3
0
ファイル: __init__.py プロジェクト: krmnn/wall
 def __init__(self, id, box):        
     super(DropboxSearchHandler, self).__init__(id, 'Dropbox ' + box.title,
         '#0000ff')
     self.box = box
     self._api = WebAPI('https://api.dropbox.com/1',
         {'access_token': box.token})
コード例 #4
0
ファイル: __init__.py プロジェクト: NoyaInRain/wall
 def __init__(self):
     super(YoutubeSearchHandler, self).__init__(randstr(), 'Youtube',
                                                '#ff0000')
     # See https://developers.google.com/youtube/v3/docs/
     self._api = WebAPI('https://www.googleapis.com/youtube/v3/',
                        {'key': YOUTUBE_API_KEY})