本文整理汇总了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))
示例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
示例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']
示例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))
示例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)
示例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
示例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)
示例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)