当前位置: 首页>>代码示例>>Python>>正文


Python Util.fetch_json方法代码示例

本文整理汇总了Python中variety.Util.Util.fetch_json方法的典型用法代码示例。如果您正苦于以下问题:Python Util.fetch_json方法的具体用法?Python Util.fetch_json怎么用?Python Util.fetch_json使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在variety.Util.Util的用法示例。


在下文中一共展示了Util.fetch_json方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: fill_queue

# 需要导入模块: from variety.Util import Util [as 别名]
# 或者: from variety.Util.Util import fetch_json [as 别名]
    def fill_queue(self):
        logger.info(lambda: "Filling Bing queue from " + self.location)

        s = Util.fetch_json(BingDownloader.BING_JSON_URL)
        for item in s['images']:
            try:
                image_url = 'https://www.bing.com' + item['url']
                filename = item['url'].split('/')[-1]
                name = filename[0:filename.find('_EN')]
                src_url = 'https://www.bing.com/gallery/#images/%s' % name
                try:
                    date = datetime.strptime(item['startdate'], '%Y%m%d').strftime('%Y-%m-%d')
                except:
                    date = item['startdate']
                extra_metadata = {
                    'sourceType': 'bing',
                    'sfwRating': 100,
                    'headline': 'Bing Photo of the Day, %s' % date,
                    'description': item['copyright'],
                }
                self.queue.append((src_url, image_url, extra_metadata))
            except:
                logger.exception(lambda: "Could not process an item in the Bing json result")

        random.shuffle(self.queue)
        logger.info(lambda: "Bing queue populated with %d URLs" % len(self.queue))
开发者ID:GLolol,项目名称:variety-deb,代码行数:28,代码来源:BingDownloader.py

示例2: ajax

# 需要导入模块: from variety.Util import Util [as 别名]
# 或者: from variety.Util.Util import fetch_json [as 别名]
 def ajax(self, url, data, error_msg_handler):
     try:
         return Util.fetch_json(url, data)
     except requests.exceptions.HTTPError, e:
         logger.exception(lambda: 'HTTPError for ' + url)
         error_msg_handler(_('Oops, server returned error (%s)') % e.response.status_code)
         raise
开发者ID:GLolol,项目名称:variety-deb,代码行数:9,代码来源:LoginOrRegisterDialog.py

示例3: get_image_url

# 需要导入模块: from variety.Util import Util [as 别名]
# 或者: from variety.Util.Util import fetch_json [as 别名]
 def get_image_url(origin_url):
     photo_id = FlickrDownloader.get_photo_id(origin_url)
     call = 'https://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key=%s&photo_id=%s&format=json&nojsoncallback=1' % \
            (API_KEY, photo_id)
     resp = Util.fetch_json(call)
     s = max(resp['sizes']['size'], key=lambda size: int(size['width']))
     return s['source']
开发者ID:GLolol,项目名称:variety-deb,代码行数:9,代码来源:FlickrDownloader.py

示例4: fill_queue

# 需要导入模块: from variety.Util import Util [as 别名]
# 或者: from variety.Util.Util import fetch_json [as 别名]
    def fill_queue(self):
        logger.info(lambda: "Reddit URL: " + self.location)

        json_url = RedditDownloader.build_json_url(self.location)
        s = Util.fetch_json(json_url)
        for item in s['data']['children']:
            try:
                data = item['data']
                image_url = data['url']
                if re.match(r'^http(s)?://imgur\.com/\w+$', image_url):
                    image_url = image_url.replace('://', '://i.') + '.jpg'

                if image_url.lower().endswith(('.jpg', '.jpeg', '.png')):
                    src_url = 'https://www.reddit.com' + data['permalink']
                    extra_metadata = {'sourceType': 'reddit'}
                    if data['over_18']:
                        extra_metadata['sfwRating'] = 0
                        if self.parent and self.parent.options.safe_mode:
                            continue
                    self.queue.append((src_url, image_url, extra_metadata))
            except Exception:
                logger.exception(lambda: "Could not process an item in the Reddit json result")

        random.shuffle(self.queue)
        logger.info(lambda: "Reddit queue populated with %d URLs" % len(self.queue))
开发者ID:GLolol,项目名称:variety-deb,代码行数:27,代码来源:RedditDownloader.py

示例5: download_one

# 需要导入模块: from variety.Util import Util [as 别名]
# 或者: from variety.Util.Util import fetch_json [as 别名]
    def download_one(self):
        logger.info(lambda: "Downloading a random image from desktoppr.co")

        response = Util.fetch_json(self.location)

        if response["response"]["review_state"] != "safe":
            logger.info(lambda: "Non-safe image returned by Desktoppr, skipping")
            return None

        origin_url = response["response"]["url"]
        image_url = response["response"]["image"]["url"]

        return self.save_locally(origin_url, image_url)
开发者ID:GLolol,项目名称:variety-deb,代码行数:15,代码来源:DesktopprDownloader.py

示例6: get_extra_metadata

# 需要导入模块: from variety.Util import Util [as 别名]
# 或者: from variety.Util.Util import fetch_json [as 别名]
 def get_extra_metadata(origin_url):
     photo_id = FlickrDownloader.get_photo_id(origin_url)
     call = 'https://api.flickr.com/services/rest/?method=flickr.photos.getInfo&api_key=%s&photo_id=%s&format=json&nojsoncallback=1' % \
            (API_KEY, photo_id)
     resp = Util.fetch_json(call)
     ph = resp['photo']
     extra_meta = {
         'headline': ph['title']['_content'],
         'description': ph['description']['_content'],
         'author': ph['owner']['realname'],
         'authorURL': 'https://www.flickr.com/photos/%s' % ph['owner']['nsid'],
         'keywords': [x['_content'] for x in ph['tags']['tag']],
     }
     return extra_meta
开发者ID:GLolol,项目名称:variety-deb,代码行数:16,代码来源:FlickrDownloader.py

示例7: fetch

# 需要导入模块: from variety.Util import Util [as 别名]
# 或者: from variety.Util.Util import fetch_json [as 别名]
 def fetch(call):
     logger.info(lambda: "Making flickr API call: " + call)
     return Util.fetch_json(call)
开发者ID:GLolol,项目名称:variety-deb,代码行数:5,代码来源:FlickrDownloader.py

示例8: search

# 需要导入模块: from variety.Util import Util [as 别名]
# 或者: from variety.Util.Util import fetch_json [as 别名]
 def search(self, _from, _to):
     url = PanoramioDownloader.API_URL % (_from, _to, self.minx, self.miny, self.maxx, self.maxy)
     logger.info(lambda: "Performing Panoramio API call: url=%s" % url)
     return Util.fetch_json(url)
开发者ID:GLolol,项目名称:variety-deb,代码行数:6,代码来源:PanoramioDownloader.py


注:本文中的variety.Util.Util.fetch_json方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。