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


Python FlickrAPI.photos_comments_getList方法代码示例

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


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

示例1: cb

# 需要导入模块: from flickrapi import FlickrAPI [as 别名]
# 或者: from flickrapi.FlickrAPI import photos_comments_getList [as 别名]
 def cb():
     fapi = FlickrAPI(config["api_key"], config["api_secret"])
     try:
         rsp = fapi.photos_comments_getList(apikey=config["api_key"], photo_id=self.image)
     except Exception, msg:
         log.debug("Exception getting comments: %s" % msg)
         return {}
开发者ID:wiredfool,项目名称:fmod,代码行数:9,代码来源:__init__.py

示例2: __init__

# 需要导入模块: from flickrapi import FlickrAPI [as 别名]
# 或者: from flickrapi.FlickrAPI import photos_comments_getList [as 别名]

#.........这里部分代码省略.........

    def getPhotosetInfo(self, pid, method):
        """Returns a string containing information about a photoset (in XML)"""

        rsp = method(api_key=self.__flickrAPIKey,
                     auth_token=self.token, photoset_id=pid)
        if self.__testFailure(rsp):
            return None
        doc = libxml2.parseDoc(rsp.xml)
        info = doc.xpathEval('/rsp/photoset')[0].serialize()
        doc.freeDoc()
        return info

    def getPhotoMetadata(self, pid):
        """Returns an array containing containing the photo metadata (as a string), and the format of the photo"""

        if self.verbose:
            print 'Requesting metadata for photo %s' % pid
        rsp = self.fapi.photos_getInfo(api_key=self.__flickrAPIKey,
                auth_token=self.token, photo_id=pid)
        if self.__testFailure(rsp):
            return None
        doc = libxml2.parseDoc(rsp.xml)
        metadata = doc.xpathEval('/rsp/photo')[0].serialize()
        doc.freeDoc()
        return [metadata, rsp.photo[0]['originalformat']]

    def getPhotoComments(self, pid):
        """Returns an XML string containing the photo comments"""

        if self.verbose:
            print 'Requesting comments for photo %s' % pid
        rsp = \
            self.fapi.photos_comments_getList(api_key=self.__flickrAPIKey,
                auth_token=self.token, photo_id=pid)
        if self.__testFailure(rsp):
            return None
        doc = libxml2.parseDoc(rsp.xml)
        comments = doc.xpathEval('/rsp/comments')[0].serialize()
        doc.freeDoc()
        return comments

    def getPhotoSizes(self, pid):
        """Returns a string with is a list of available sizes for a photo"""

        rsp = self.fapi.photos_getSizes(api_key=self.__flickrAPIKey,
                auth_token=self.token, photo_id=pid)
        if self.__testFailure(rsp):
            return None
        return rsp

    def getOriginalPhoto(self, pid):
        """Returns a URL which is the original photo, if it exists"""

        source = None
        rsp = self.getPhotoSizes(pid)
        if rsp == None:
            return None
        for s in rsp.sizes[0].size:
            if s['label'] == 'Original':
                source = s['source']
        for s in rsp.sizes[0].size:
            if s['label'] == 'Video Original':
                source = s['source']
        return [source, s['label'] == 'Video Original']
开发者ID:skvidal,项目名称:offlickr,代码行数:69,代码来源:offlickr.py

示例3: importFromFlickr

# 需要导入模块: from flickrapi import FlickrAPI [as 别名]
# 或者: from flickrapi.FlickrAPI import photos_comments_getList [as 别名]
def importFromFlickr():

    if g.user is None:
        return jsonify(result = False, error = "You need to be logged in to import from Flickr")
        
    if not g.user.flickr_auth:
        return jsonify(result = False, error = "Your account has not been authenticated with Flickr")

    try:  # Yes yes, a massive try block, the horror! But almost every single line in here throws an error from FlickrAPI
        photoID = request.form.get('photoID')
        api_key = os.environ['PARAM1']
        api_secret = os.environ['PARAM2']
        flickr = FlickrAPI(api_key, api_secret, store_token = False)

        # Get original photo's URL
        sizes = flickr.photos_getSizes(photo_id = photoID).find('sizes')[-1]
        photo_url = sizes.attrib['source']
        img_width = int(sizes.attrib['width'])   # necessary to correctly scale notes
        img_height = int(sizes.attrib['height'])

        # Pull a blob of most of the photo's metadata
        photo_info = flickr.photos_getInfo(photo_id = photoID).find('photo')

        # Check if the person importing this photo actually owns it
        flickr_screen_name = photo_info.find('owner').attrib['username']
        if flickr_screen_name.lower() != g.user.name.lower():
            return jsonify(result = False, error = 'You dog!  You don\'t own this photo!  %s does.  For shame.' % flickr_screen_name)

        # Pull photo's title, desc, timestamps from metadata blob
        flickr_owner_id = photo_info.find('owner').attrib['nsid']  # used to retrieve views
        title = photo_info.find('title').text
        desc = photo_info.find('description').text
        time_taken = photo_info.find('dates').attrib['taken']  # '2013-06-22 11:16:32' ... wtf?
        time_posted = photo_info.find('dates').attrib['posted']  # '1372279163'

        # flickr notes are in a 0..500px coordinate space, where 500 maps to max(img_width, img_height)
        # brickr notes are normalized to a 0..100 % coordinate space, regardless of image aspect ratio (because I'm smarter)
        # flickr notes don't have timestamp info
        scale_w = 500 if img_width >= img_height else (500 / img_height * img_width)
        scale_h = 500 if img_width < img_height else (500 / img_width * img_height)
        notes = []
        for note in photo_info.find('notes'):
            notes.append({
                'user_id': note.attrib['author'],
                'screen_name': note.attrib['authorname'],
                'text': note.text,
                'x': int(note.attrib['x']) / scale_w * 100,
                'y': int(note.attrib['y']) / scale_h * 100,
                'w': int(note.attrib['w']) / scale_w * 100,
                'h': int(note.attrib['h']) / scale_h * 100
            })

        # Photo tags are easy
        tags = []
        for tag in photo_info.find('tags'):
            if tag.attrib['machine_tag'] != '1':  # Ignore ugly automatically created inivisible-to-users tags
                tags.append(tag.attrib['raw'])

        # Import comments - needs its own Flickr API call
        comments = []
        if int(photo_info.find('comments').text) > 0:
            comment_rsp = flickr.photos_comments_getList(photo_id = photoID).find('comments')
            for comment in comment_rsp:
                comments.append({
                    'user_id': comment.attrib.get('author'),
                    'screen_name': comment.attrib.get('authorname'),
                    'timestamp': comment.attrib.get('datecreate'),
                    'iconfarm': comment.attrib.get('iconfarm'),
                    'iconserver': comment.attrib.get('iconserver'),
                    'text': comment.text
                })

        # Import Favorites.  These come in at most 50 per request. Another dedicated Flickr API call
        favorites = []
        favorite_rsp = flickr.photos_getFavorites(photo_id = photoID, per_page = '50').find('photo')
        for fav in favorite_rsp:
            favorites.append({
                'user_id': fav.attrib.get('nsid'),
                'screen_name': fav.attrib.get('username'),
                'timestamp': fav.attrib.get('favedate'),
                'iconfarm': comment.attrib.get('iconfarm'),
                'iconserver': comment.attrib.get('iconserver')
            })

        fav_page_count = int(favorite_rsp.attrib['pages'])
    
        if fav_page_count > 1:
            for i in range(2, fav_page_count + 1):
                favorite_rsp = flickr.photos_getFavorites(photo_id = photoID, page = str(i), per_page = '50').find('photo')
                for fav in favorite_rsp:
                    favorites.append({
                        'user_id': fav.attrib['nsid'],
                        'screen_name': fav.attrib.get('username'),
                        'timestamp': fav.attrib.get('favedate'),
                        'iconfarm': comment.attrib.get('iconfarm'),
                        'iconserver': comment.attrib.get('iconserver')
                    })

        # View count
        # There's no direct flickr API to get a photo's view count (weird)
#.........这里部分代码省略.........
开发者ID:remig,项目名称:brickr,代码行数:103,代码来源:photos.py


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