本文整理汇总了Python中flickrapi.FlickrAPI方法的典型用法代码示例。如果您正苦于以下问题:Python flickrapi.FlickrAPI方法的具体用法?Python flickrapi.FlickrAPI怎么用?Python flickrapi.FlickrAPI使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flickrapi
的用法示例。
在下文中一共展示了flickrapi.FlickrAPI方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_flickr_image_by_keyword
# 需要导入模块: import flickrapi [as 别名]
# 或者: from flickrapi import FlickrAPI [as 别名]
def get_flickr_image_by_keyword(keyword):
"""Given a keyword, search Flickr for it and return a slightly-random result as a file descriptor"""
logging.info("Getting {} from Flickr".format(keyword))
flickr = flickrapi.FlickrAPI(FLICKR_KEY, FLICKR_SECRET, format='etree')
result = flickr.photos.search(per_page=100,
text=keyword,
tag_mode='all',
content_type=1,
tags=keyword,
extras='url_o,url_l',
sort='relevance')
# Randomize the result set
img_url = None
photos = [p for p in result[0]]
while img_url is None and len(photos) > 0:
photo = photos[0]
img_url = photo.get('url_o') or photo.get('url_l')
photos.pop()
if not img_url:
raise Exception("Couldn't find a Flickr result for %s" % keyword)
logging.info(img_url)
img_file = requests.get(img_url, stream=True)
return BytesIO(img_file.content)
示例2: flickrAPIUser
# 需要导入模块: import flickrapi [as 别名]
# 或者: from flickrapi import FlickrAPI [as 别名]
def flickrAPIUser(username):
return flickrapi.FlickrAPI(api_key, api_secret, format='parsed-json', username=username)
示例3: auth
# 需要导入模块: import flickrapi [as 别名]
# 或者: from flickrapi import FlickrAPI [as 别名]
def auth():
return flickrapi.FlickrAPI(settings.FLICKR_KEY,
settings.FLICKR_SECRET,
format='parsed-json',
store_token=False,
cache=True)
示例4: __init__
# 需要导入模块: import flickrapi [as 别名]
# 或者: from flickrapi import FlickrAPI [as 别名]
def __init__(self, api_key, api_secret, username):
assert api_key, "api_key not supplied<%s>" % api_key
assert api_secret, "api_secret not supplied<%s>" % api_secret
assert username, "username not supplied<%s>" % username
try:
self.api = flickrapi.FlickrAPI(api_key, api_secret, username = username)
except flickrapi.exceptions.FlickrError as e:
raise Error(e)
logger.debug('%s' % self.api)
示例5: main
# 需要导入模块: import flickrapi [as 别名]
# 或者: from flickrapi import FlickrAPI [as 别名]
def main():
site = wikipedia.getSite(u'commons', u'commons')
wikipedia.setSite(site)
imagerecat.initLists()
flickr = flickrapi.FlickrAPI(api_key)
groupId = '[email protected]'
#photos = flickr.flickr.groups_search(text='[email protected]', per_page='10') = [email protected]
for photoId in getPhotosInGroup(flickr=flickr, group_id=groupId):
(photoInfo, photoSizes) = getPhoto(flickr=flickr, photo_id=photoId)
if isAllowedLicense(photoInfo=photoInfo):
tags=getTags(photoInfo=photoInfo)
if photoCanUpload(tags=tags):
# Get the url of the largest photo
photoUrl = getPhotoUrl(photoSizes=photoSizes)
# Download this photo
photo = downloadPhoto(photoUrl=photoUrl)
# Check if it exists at Commons
duplicates = findDuplicateImages(photo=photo)
if duplicates:
wikipedia.output(u'Found duplicate image at %s' % duplicates.pop())
else:
flinfoDescription = getFlinfoDescription(photoId=photoId)
tagDescription = getTagDescription(tags=tags)
tagCategories = getTagCategories(tags)
filename = getFilename(photoInfo=photoInfo)
#print filename
photoDescription = buildDescription(flinfoDescription, tagDescription, tagCategories)
if (wikipedia.Page(title=u'File:'+ filename, site=wikipedia.getSite()).exists()):
# I should probably check if the hash is the same and if not upload it under a different name
wikipedia.output(u'File:' + filename + u' already exists!')
else:
#Do the actual upload
#Would be nice to check before I upload if the file is already at Commons
#Not that important for this program, but maybe for derived programs
bot = upload.UploadRobot(url=photoUrl, description=photoDescription, useFilename=filename, keepFilename=True, verifyDescription=False)
bot.run()
wikipedia.output('All done')
示例6: getImage
# 需要导入模块: import flickrapi [as 别名]
# 或者: from flickrapi import FlickrAPI [as 别名]
def getImage(refstring):
tagged = tag(refstring)
nouns = [word for word,pos in tagged if pos == 'NNP' or pos == 'NP' or pos == 'NN']
try:
query = random.choice(nouns)
except IndexError:
#somehow this string has no nouns!
if DEBUG: print("Paragraph with no nouns:\n" + refstring, file=sys.stderr)
return None
if DEBUG: print(query, file=sys.stderr)
flickr = flickrapi.FlickrAPI(flickr_key, flickr_secret, format='parsed-json')
result = flickr.photos_search(api_key = flickr_key, text = query, privacy_filter = 1, safe_search=1, sort='interestingness-desc', orientation="landscape")
try:
pick = random.choice(result['photos']['photo'])
url = 'https://farm' + str(pick['farm']) + '.staticflickr.com/' + str(pick['server']) + '/' + str(pick['id']) + '_' + str(pick['secret']) + '_z.jpg'
except IndexError:
# there were no results, so the random.choice call failed above. This is OK, we'll just move on.
url = None
image = {}
image['url'] = url
image['noun'] = query
return image
#given a list of sentences, return a list of paragraphs
示例7: __init__
# 需要导入模块: import flickrapi [as 别名]
# 或者: from flickrapi import FlickrAPI [as 别名]
def __init__(self, api_key=None, cache='/tmp/ecasa'):
"""Initialize API, login to flickr servers"""
PictureApi.__init__(self, cache=cache)
self.flickr_api = flickrapi.FlickrAPI(api_key)
示例8: cli
# 需要导入模块: import flickrapi [as 别名]
# 或者: from flickrapi import FlickrAPI [as 别名]
def cli(config, config_file, flickr_api, flickr_secret,
pybossa_api, pybossa_server, pybossa_project):
"""Create the cli command line."""
import flickrapi
home = expanduser("~")
if os.path.isfile(os.path.join(home, '.trapcamera.cfg')):
# FLICKR config
config.parser.read(os.path.join(home, '.trapcamera.cfg'))
config.flickr_api = config.parser.get('flickr', 'api')
config.flickr_secret = config.parser.get('flickr', 'secret')
config.flickr_license_id = config.parser.get('flickr', 'license_id')
config.flickr_photoset_name = config.parser.get('flickr',
'photoset_name')
# DATA config
config.offline = config.parser.get('data', 'offline')
config.data = config.parser.get('data', 'images')
# PYBOSSA config
config.pybossa_api = config.parser.get('pybossa', 'api_key')
config.pybossa_server = config.parser.get('pybossa', 'endpoint')
config.pybossa_project = config.parser.get('pybossa', 'project_id')
# CAMERA config
config.camera_sharpness = literal_eval(config.parser.get('camera', 'sharpness'))
config.camera_contrast = literal_eval(config.parser.get('camera', 'contrast'))
config.camera_brightness = literal_eval(config.parser.get('camera', 'brightness'))
config.camera_saturation = literal_eval(config.parser.get('camera', 'saturation'))
config.camera_iso = literal_eval(config.parser.get('camera', 'ISO'))
config.camera_video_stabilization = literal_eval(config.parser.get('camera',
'video_stabilization'))
config.camera_exposure_compensation = literal_eval(config.parser.get('camera', 'exposure_compensation'))
config.camera_exposure_mode = literal_eval(config.parser.get('camera', 'exposure_mode'))
config.camera_meter_mode = literal_eval(config.parser.get('camera', 'meter_mode'))
config.camera_awb_mode = literal_eval(config.parser.get('camera', 'awb_mode'))
config.camera_image_effects = literal_eval(config.parser.get('camera', 'image_effect'))
config.camera_color_effects = literal_eval(config.parser.get('camera', 'color_effects'))
config.camera_rotation = literal_eval(config.parser.get('camera', 'rotation'))
config.camera_hflip = literal_eval(config.parser.get('camera', 'hflip'))
config.camera_vflip = literal_eval(config.parser.get('camera', 'vflip'))
config.camera_crop = literal_eval(config.parser.get('camera', 'crop'))
config.camera_resolution = literal_eval(config.parser.get('camera', 'resolution'))
if flickr_api:
config.flickr_api = flickr_api
if flickr_secret:
config.flickr_secret = flickr_secret
config.flickrapi = flickrapi.FlickrAPI(config.flickr_api,
config.flickr_secret,
format='parsed-json')
pbclient.set('endpoint', config.pybossa_server)
pbclient.set('api_key', config.pybossa_api)
config.pbclient = pbclient
示例9: main
# 需要导入模块: import flickrapi [as 别名]
# 或者: from flickrapi import FlickrAPI [as 别名]
def main():
wikipedia.setSite(wikipedia.getSite(u'commons', u'commons'))
#Get the api key
if config.flickr['api_key']:
flickr = flickrapi.FlickrAPI(config.flickr['api_key'])
else:
wikipedia.output('Flickr api key not found! Get yourself an api key')
wikipedia.output('Any flickr user can get a key at http://www.flickr.com/services/api/keys/apply/')
return
group_id = u'[email protected]'
addCategory = u'Rijksmonumenten'
removeCategories = True
autonomous = True
totalPhotos = 0
uploadedPhotos = 0
# Do we mark the images as reviewed right away?
if config.flickr['review']:
flickrreview = config.flickr['review']
else:
flickrreview = False
# Set the Flickr reviewer
if config.flickr['reviewer']:
reviewer = config.flickr['reviewer']
elif 'commons' in config.sysopnames['commons']:
print config.sysopnames['commons']
reviewer = config.sysopnames['commons']['commons']
elif 'commons' in config.usernames['commons']:
reviewer = config.usernames['commons']['commons']
else:
reviewer = u''
for photo_id in flickrripper.getPhotos(flickr=flickr, group_id=group_id):
uploadedPhotos += processPhoto(flickr, photo_id, flickrreview, reviewer, addCategory, removeCategories, autonomous)
totalPhotos += 1
wikipedia.output(u'Finished running')
wikipedia.output(u'Total photos: ' + str(totalPhotos))
wikipedia.output(u'Uploaded photos: ' + str(uploadedPhotos))