""" flickr.py Copyright 2004-2006 James Clarke <james@jamesclarke.info> Portions Copyright 2007-2008 Joshua Henderson <joshhendo@gmail.com> THIS SOFTWARE IS SUPPLIED WITHOUT WARRANTY OF ANY KIND, AND MAY BE COPIED, MODIFIED OR DISTRIBUTED IN ANY WAY, AS LONG AS THIS NOTICE AND ACKNOWLEDGEMENT OF AUTHORSHIP REMAIN. 2007-12-17 For an upto date TODO list, please see: http://code.google.com/p/flickrpy/wiki/TodoList For information on how to use the Authentication module, plese see: http://code.google.com/p/flickrpy/wiki/UserAuthentication 2006-12-19 Applied patches from Berco Beute and Wolfram Kriesing. """ __author__ = "James Clarke <james@jamesclarke.info>" __version__ = "$Rev$" __date__ = "$Date$" __copyright__ = "Copyright: 2004-2010 James Clarke; Portions: 2007-2008 Joshua Henderson; Portions: 2011 Andrei Vlad Vacariu" from urllib import urlencode, urlopen from xml.dom import minidom import hashlib import os HOST = 'http://flickr.com' API = '/services/rest' # set these here or using flickr.API_KEY in your application API_KEY = '850823c6a553edf0f0eb3569c39356c6' API_SECRET = '1fc3f3479f8022f7' email = None password = None AUTH = False debug = False # The next 2 variables are only importatnt if authentication is used # this can be set here or using flickr.tokenPath in your application # this is the path to the folder containing tokenFile (default: token.txt) tokenPath = '' # this can be set here or using flickr.tokenFile in your application # this is the name of the file containing the stored token. tokenFile = 'token.txt' class FlickrError(Exception): pass class Photo(object): """Represents a Flickr Photo.""" __readonly = ['id', 'secret', 'server', 'farm', 'isfavorite', 'license', 'rotation', 'owner', 'dateposted', 'datetaken', 'takengranularity', 'title', 'description', 'ispublic', 'isfriend', 'isfamily', 'cancomment', 'canaddmeta', 'comments', 'tags', 'permcomment', 'permaddmeta', 'url', 'views'] #XXX: Hopefully None won't cause problems def __init__(self, id, owner=None, dateuploaded=None, title=None, description=None, ispublic=None, isfriend=None, isfamily=None, cancomment=None, canaddmeta=None, comments=None, tags=None, secret=None, isfavorite=None, server=None, farm=None, license=None, rotation=None, url=None, views=None): """Must specify id, rest is optional.""" self.__loaded = False self.__cancomment = cancomment self.__canaddmeta = canaddmeta self.__comments = comments self.__dateuploaded = dateuploaded self.__description = description self.__id = id self.__license = license self.__isfamily = isfamily self.__isfavorite = isfavorite self.__isfriend = isfriend self.__ispublic = ispublic self.__owner = owner self.__rotation = rotation self.__secret = secret self.__server = server self.__farm = farm self.__tags = tags self.__title = title self.__dateposted = None self.__datetaken = None self.__takengranularity = None self.__permcomment = None self.__permaddmeta = None self.__url = None self.__views = None def __setattr__(self, key, value): if key in self.__class__.__readonly: raise AttributeError("The attribute %s is read-only." % key) else: super(Photo, self).__setattr__(key, value) def _val(self, key): if key in self.__class__.__readonly: return super(Photo, self).__getattribute__("_%s__%s" % (self.__class__.__name__, key)) else: return super(Photo, self).__getattribute__(key) def __getattr__(self, key): val = self._val(key) if val == None and not self.__loaded: self._load_properties() val = self._val(key) return val def _load_properties(self): """Loads the properties from Flickr.""" self.__loaded = True method = 'flickr.photos.getInfo' data = _doget(method, photo_id=self.id) photo = data.rsp.photo self.__secret = photo.secret self.__server = photo.server self.__farm = photo.farm self.__isfavorite = photo.isfavorite self.__license = photo.license self.__rotation = photo.rotation owner = photo.owner self.__owner = User(owner.nsid, username=owner.username, realname=owner.realname, location=owner.location) self.__title = photo.title.text self.__description = photo.description.text self.__ispublic = photo.visibility.ispublic self.__isfriend = photo.visibility.isfriend self.__isfamily = photo.visibility.isfamily self.__dateposted = photo.dates.posted self.__datetaken = photo.dates.taken self.__takengranularity = photo.dates.takengranularity self.__cancomment = photo.editability.cancomment self.__canaddmeta = photo.editability.canaddmeta self.__comments = photo.comments.text self.__url = photo.urls.url.text self.__views = photo.views try: self.__permcomment = photo.permissions.permcomment self.__permaddmeta = photo.permissions.permaddmeta except AttributeError: self.__permcomment = None self.__permaddmeta = None #TODO: Implement Notes? if hasattr(photo.tags, "tag"): if isinstance(photo.tags.tag, list): self.__tags = [Tag(tag.id, User(tag.author), tag.raw, tag.text) for tag in photo.tags.tag] else: tag = photo.tags.tag self.__tags = [Tag(tag.id, User(tag.author), tag.raw, tag.text)] def __str__(self): return '<Flickr Photo %s>' % self.id def setTags(self, tags): """Set the tags for current photo to list tags. (flickr.photos.settags) """ method = 'flickr.photos.setTags' tags = uniq(tags) _dopost(method, auth=True, photo_id=self.id, tags=tags) self._load_properties() def addTags(self, tags): """Adds the list of tags to current tags. (flickr.photos.addtags) """ method = 'flickr.photos.addTags' if isinstance(tags, list): tags = uniq(tags) _dopost(method, auth=True, photo_id=self.id, tags=tags) #load properties again self._load_properties() def removeTag(self, tag): """Remove the tag from the photo must be a Tag object. (flickr.photos.removeTag) """ method = 'flickr.photos.removeTag' tag_id = '' try: tag_id = tag.id except AttributeError: raise FlickrError, "Tag object expected" _dopost(method, auth=True, photo_id=self.id, tag_id=tag_id) self._load_properties() def setMeta(self, title=None, description=None): """Set metadata for photo. (flickr.photos.setMeta)""" method = 'flickr.photos.setMeta' if title is None: title = self.title if description is None: description = self.description _dopost(method, auth=True, title=title, description=description, photo_id=self.id) self.__title = title self.__description = description def getAllContexts(self): """Retrieves lists of the pools/sets the photo is in""" method = 'flickr.photos.getAllContexts' data = _doget(method, photo_id=self.id) d = {'pools': [], 'sets': []} if hasattr(data.rsp, "pool"):
相关知识
花卉识别数据图片花卉数据图片
有哪些手机识别花草的app 拍照识别植物的软件推荐
晋宁花卉产业借科技再发力
缤纷花卉靓中国
第二十一届中国昆明国际花卉展集中展示云南花卉产业丰硕成果
智能花卉识别软件下载安装
我国成世界最大花卉生产国
“五芳獻瑞”成熱門年宵花 提供買花諮詢和設計服務 七大花卉市場集中連片上新 打造豐臺花卉金名片
最鲜艳的“花卉”拍卖
最全花名目录集:花花世界迷人眼
网址: FlowersRecognition(花卉识别数据集).zip https://m.huajiangbk.com/newsview165.html
上一篇: 识花草小程序下载,识花草APP小 |
下一篇: 花草识别扫一扫app官方版202 |