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


Python FlickrAPI.testFailure方法代码示例

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


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

示例1: FwiktrFlickrRetriever

# 需要导入模块: from flickrapi import FlickrAPI [as 别名]
# 或者: from flickrapi.FlickrAPI import testFailure [as 别名]
class FwiktrFlickrRetriever(FwiktrServiceManager):
    transformList = [FwiktrFlickrFuckItSelectionTransform(), FwiktrFlickrFullANDSelectionTransform()]
    def __init__(self):
        self._pic_info = []
        FwiktrServiceManager.__init__(self)
        self.name = "Flickr"

    def _SetupService(self):
        self._fapi = FlickrAPI(self._GetOption('flickr_api_key'), self._GetOption('flickr_api_secret'))

    def GetPictureXML(self):
        return flickr_info_xml

    def GetPictureData(self):
        return {'picture_title':cgi.escape(self._pic_info['title']), 'picture_info':self._GetPictureSpecificData()}
        
    def _GetPictureSpecificData(self):
        return flickr_info_xml % {'flickr_server':self._pic_info['server'], 'flickr_farm':self._pic_info['farm'], 'flickr_photo_id':self._pic_info['id'], 'flickr_secret':self._pic_info['secret'], 'flickr_owner_id':self._pic_info['owner']}

    def GetNewPicture(self, tag_list):
        try:
            if len(tag_list) > 20:
                culler = FwiktrFlickrTagCullTransform()
                tag_list = culler.RunTransform(tag_list)
            tag_string = ','.join(tag_list)
            if(tag_string == ""): return False
            pic = FwiktrFlickrFullANDSelectionTransform()
            rsp = self._fapi.photos_search(api_key=self._GetOption('flickr_api_key'),tags=tag_string,tag_mode='all')
            self._fapi.testFailure(rsp)
            print rsp.photos[0]['total']
            if(int(rsp.photos[0]['total']) == 0):
                pic = FwiktrFlickrFuckItSelectionTransform()
                rsp = self._fapi.photos_search(api_key=self._GetOption('flickr_api_key'),tags=tag_string,tag_mode='any')
                print rsp.photos[0]['total']
                self._fapi.testFailure(rsp)
            if(int(rsp.photos[0]['total']) == 0): 
                return False
            rand_index = random.randint(0, min(int(rsp.photos[0]['perpage']), int(rsp.photos[0]['total'])))
            self._pic_info = rsp.photos[0].photo[rand_index]            
            pic.RunTransform({'total':rsp.photos[0]['total'],'picked':rand_index})
            return True 
        except:
            return False
开发者ID:qdot,项目名称:fwiktr,代码行数:45,代码来源:fwiktr_web.py

示例2: Shell

# 需要导入模块: from flickrapi import FlickrAPI [as 别名]
# 或者: from flickrapi.FlickrAPI import testFailure [as 别名]
class Shell(cmdln.Cmdln):
    r"""ci2 -- the new Code Intel, a tool for working with source code

    usage:
        ${name} SUBCOMMAND [ARGS...]
        ${name} help SUBCOMMAND

    ${option_list}
    ${command_list}
    ${help_list}
    """
    name = "batchr"
    #XXX There is a bug in cmdln.py alignment when using this. Leave it off
    #    until that is fixed.
    #helpindent = ' '*4

    def _setup(self, opts):
        # flickr auth information:
        self.flickrAPIKey = os.environ['FLICKR_BATCHR_KEY']
        self.flickrSecret = os.environ['FLICKR_BATCHR_SECRET']
        try:
            gui = opts.gui
        except AttributeError: # really wish I could just test "gui" in opts
            gui = False
        self.progress = progressBar("Flickr Shell", indeterminate=True, gui=gui)

        self.progress.update("Logging In...")
        # make a new FlickrAPI instance
        self.fapi = FlickrAPI(self.flickrAPIKey, self.flickrSecret)

        # do the whole whatever-it-takes to get a valid token:
        self.token = self.fapi.getToken(browser="Firefox")


    def do_listsets(self, subcmd, opts, *args):
        """List set ids and set titles (with substring title matches)"""
        self._setup(opts)
        kw = dict(api_key=self.flickrAPIKey,
                  auth_token=self.token)
        rsp = self.fapi.photosets_getList(**kw)
        self.fapi.testFailure(rsp)
        sets = rsp.photosets[0].photoset
        for set in sets:
            title = set.title[0].elementText
            match = True
            if args:
                match = False
                for word in args:
                    if word.lower() in title.lower():
                        match = True
                        break
            if match:
                print set['id']+':', title, '('+set['photos']+ " photos)"
        self.progress.finish()

    @cmdln.option("-b", "--base", dest="base",
                  default="./photos",
                  help="the directory we want to download to")
    @cmdln.option("-F", "--format", dest="format",
                  help="the file layout format to use within the base directory (default is %(year)s/%(month_name)s/%(size)s/%(id)s.jpg",
                  default="%(year)s/%(month_name)s/%(size)s/%(id)s.jpg")
    @cmdln.option("-f", "--force", action="store_true",
                  help="force downloads even if files with same name already exist")
    @cmdln.option("-y", "--year", dest="year", type='int',
                  help="the year we want backed up")
    @cmdln.option("-m", "--month", dest="month", type='int',
                  help="the month we want backed up")
    @cmdln.option("-s", "--size", dest="size", default='-',
                  nargs=1,
                  help="the size we want downloaded: one of: s t m b - o")
    @cmdln.option("-t", "--test", action="store_true",
                  help="Just get the URLs (don't download images) -- implies -l")
    @cmdln.option("--tags",
                  help="Tags (separatead by commas)")
    @cmdln.option("-S", "--set",
                  help="Set id (use listsets command to get them)")
    @cmdln.option("-l", "--list", action="store_true",
                  help="List URLs being downloaded instead of using progress bar")
    @cmdln.option("--gui", action="store_true",
                  help="use Cocoa progress bar on OS X")
    def do_download(self, subcmd, opts):
        """Download images based on search criteria (dates, tags, sets)

        ${cmd_usage}
        ${cmd_option_list}
        Any errors will be printed. Returns the number of errors (i.e.
        exit value is 0 if there are no consistency problems).
        """
        urls = self._search(opts)
        self.progress.reset("Getting Photo Info")
        count = 0
        downloadeds = 0
        bad_ones =  []
        try:
            try:
                for (id, url, original_url, date_taken) in urls:
                    year, month, day = parse_date_taken(date_taken)
                    month_name = calendar.month_name[month]
                    size = pretty_size[opts.size]
                    filename = opts.format % locals()
#.........这里部分代码省略.........
开发者ID:davidascher,项目名称:batchr,代码行数:103,代码来源:batchr.py

示例3: FlickrAPI

# 需要导入模块: from flickrapi import FlickrAPI [as 别名]
# 或者: from flickrapi.FlickrAPI import testFailure [as 别名]
#!/usr/bin/env python

#test comment
import sys
from flickrapi import FlickrAPI

# Autenticazione
flickrAPIKey = "ea9b8730af07cd76f6dc4fde27744b74"  # API key
flickrSecret = "45dfeeb5abec1ff9"                  # shared "secret"
gruppo='[email protected]'

# crea una istanza di FlickrAPI 
fapi = FlickrAPI(flickrAPIKey, flickrSecret)

# ottieni un token valido
token = fapi.getToken(browser="firefox", perms="write")
rsp = fapi.auth_checkToken(api_key=flickrAPIKey, auth_token=token)
fapi.testFailure(rsp)

#grabba tutte le foto con il group id specificato
rsp = fapi.groups_pools_getPhotos(auth_token=token,api_key=flickrAPIKey,group_id=gruppo)
fapi.testFailure(rsp)

for a in rsp.photos[0].photo:
	rsp = fapi.groups_pools_remove(api_key=flickrAPIKey,photo_id=a['id'],auth_token=token,group_id=gruppo)
	fapi.testFailure(rsp,exit=0)


开发者ID:BackupTheBerlios,项目名称:febstools-svn,代码行数:28,代码来源:remover.py

示例4: remap

# 需要导入模块: from flickrapi import FlickrAPI [as 别名]
# 或者: from flickrapi.FlickrAPI import testFailure [as 别名]
def remap(line):
    if flickr.match(line):
        global fapi, token
        if fapi is None:
            fapi = FlickrAPI(flickrAPIKey, flickrSecret)
            token = fapi.getToken(browser="lynx")

        id = flickr.match(line).group(1)
        print "  talking to Flickr about: ",id
        
        rsp = fapi.photos_getInfo(api_key=flickrAPIKey,auth_token=token,photo_id=id)
        fapi.testFailure(rsp)
        description = rsp.photo[0].description[0].elementText
        URL = rsp.photo[0].urls[0].url[0].elementText

        rsp = fapi.photos_getSizes(api_key=flickrAPIKey,auth_token=token,photo_id=id)
        fapi.testFailure(rsp)
        localbig = ''
        for x in rsp.sizes[0].size:
            if x.attrib['label'] == 'Large':
                localbig = x.attrib['source'].split('/')[-1]
                os.system('curl -o html/photos/%s "%s"' % (localbig, x.attrib['source']))
                
        for x in rsp.sizes[0].size:
            #if x.attrib['label'] == 'Square':
            if x.attrib['label'] == 'Small':
                localpath = x.attrib['source'].split('/')[-1]
                big = ''
                if localbig != '':
                    big = '[<a href="photos/%s">local</a>]' % localbig
                os.system('curl -o html/photos/%s "%s"' % (localpath, x.attrib['source']))
                return '<div class="photo"><a href="%(url)s"><img src="%(src)s" height="%(height)s" width="%(width)s" alt="%(alt)s" /></a><div class="caption">%(caption)s%(localbig)s</div></div>' % \
                       {'src':'photos/%s'%localpath,#x.attrib['source'],
                        'height':x.attrib['height'],
                        'width':x.attrib['width'],
                        'caption': description,
                        'url':URL,
                        'alt':description,
                        'localbig':big
                        }

    elif localphoto.match(line):
        m = localphoto.match(line)
        caption = m.group(1)
        id = m.group(2)
        thumb = id.split('.')[0] + '-thumb.jpeg'
        if not os.path.exists(thumb):
            cmd = 'convert -resize 240x240 ' + os.path.join(BASE,'photos/'+id) + ' ' + os.path.join(BASE,'photos/'+thumb)
            print cmd
            os.system(cmd)

        ## FIXME size probably wrong; figure out real size of
        ## thumbnail or at least whether its rotated or not
        return '<div class="photo"><a href="photos/%s"><img src="photos/%s" height="180" width="240" alt="%s" /></a><div class="caption">%s</div></div>' % (id, thumb, caption, caption)
    

    elif googledoc.match(line):
        url = googledoc.match(line).group(1)
        print "  talking to Google about:",url
        html = googledocToHtml(urlopen(url).readlines())
        return html
                
    elif resultdoc.match(line):
        name = resultdoc.match(line).group(1)
        url = resultdoc.match(line).group(2)
        print "  talking to Google about results:",url
        html = resultdocToHtml(urlopen(url).readlines(), url, name)
        return html

    elif rideschedule.match(line):
        year = rideschedule.match(line).group(1).strip()
        region = rideschedule.match(line).group(2).strip().lower()
        if not year in ridelist.keys():
            print "  talking to Google about schedule:",year,region
            if int(year) > 2010:
                ridelist[year] = rideScheduleCsvToRideList(urlopen(PRELIM_RIDE_SCHEDULES[year]).readlines(), year)
            else:
                ridelist[year] = pre2010rideScheduleCsvToRideList(urlopen(PRELIM_RIDE_SCHEDULES[year]).readlines(), year)
                print year,ridelist[year]

        officialkey = region.strip().lower() + ':' + year.strip()
        if OFFICIAL_RIDE_SCHEDULES.has_key(officialkey):
            print "  talking to Google about official schedule",year,region,OFFICIAL_RIDE_SCHEDULES[officialkey]
            if int(year.strip()) <= 2010:
                html = officialRideScheduleToHtml(urlopen(OFFICIAL_RIDE_SCHEDULES[officialkey]).readlines(), ridelist[year], year, region)
            else:
                html = officialRideListToHtml(ridelist[year], year, region)

        else:
            print "NO official ride schedule yet for",region,year,officialkey
            html = rideListToHtml(ridelist[year], region)
        return html
    
    elif membership.match(line):
        url = membership.match(line).group(1).strip()
        html = membershipToHtml(urlopen(url).readlines())
        return html

    return line
开发者ID:sebedale04,项目名称:abrando,代码行数:101,代码来源:build.py

示例5: FlickrAPI

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

# flickr auth information:
flickrSecret = "3fbf7144be7eca28"                  # shared "secret"

flickrAPIKey = "f8aa9917a9ae5e44a87cae657924f42d"  # API key
# make a new FlickrAPI instance
fapi = FlickrAPI(flickrAPIKey, flickrSecret)

# do the whole whatever-it-takes to get a valid token:
token = fapi.getToken(browser="/usr/bin/firefox")

# get my favorites
rsp = fapi.favorites_getList(api_key=flickrAPIKey,auth_token=token)
fapi.testFailure(rsp)

#print 'Photosets: '
print fapi.photosets_getList(api_key=flickrAPIKey, auth_token=token)
rsp = fapi.photosets_getList(api_key=flickrAPIKey, auth_token=token)
fapi.testFailure(rsp)
#print photoSets
#print ', '.join([str(set.title) for set in photoSets])

#person = fapi.flickr_people_getInfo(user_id="tuxmann")
#print person.username

# and print them
if hasattr(rsp.photosets[0], "photoset"):
	print 'yeup!'
else:
开发者ID:Xirg,项目名称:flickrfs-old,代码行数:33,代码来源:test.py


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