Follow and download user's favorites photos on Flickr: Difference between revisions
(Created page with "<code lang="python"> #!/usr/bin/python import flickrapi, random, urllib2 useragent = "Mozilla/5.001 (windows; U; NT4.0; en-US; rv:1.0) Gecko/25250101" api_key = 'xxxxxxxxxxxxxx...") |
No edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
< | <source lang="python"> | ||
#!/usr/bin/python | #!/usr/bin/python | ||
import flickrapi, random, urllib2 | import flickrapi, random, urllib2 | ||
Line 20: | Line 20: | ||
for photo in t_fav[0]: | for photo in t_fav[0]: | ||
p = flickr.photos_getInfo(photo_id=photo.attrib['id']) | p = flickr.photos_getInfo(photo_id=photo.attrib['id']) | ||
# http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{secret}.jpg | # http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{secret}.jpg | ||
Line 33: | Line 32: | ||
t_pool.append(photo.attrib['owner']) | t_pool.append(photo.attrib['owner']) | ||
</ | </source> | ||
[[Category: Cookbook]] |
Latest revision as of 18:31, 14 January 2011
#!/usr/bin/python
import flickrapi, random, urllib2
useragent = "Mozilla/5.001 (windows; U; NT4.0; en-US; rv:1.0) Gecko/25250101"
api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
flickr = flickrapi.FlickrAPI(api_key)
t_pool = ['0000000']
while True:
t_id = random.choice(t_pool)
t_username = flickr.people_getInfo(user_id=t_id)[0].find('username').text
print '*** id: '+t_id, 'username: '+t_username+' ***'
t_fav = flickr.favorites_getPublicList(user_id=t_id)
t_pool = []
for photo in t_fav[0]:
p = flickr.photos_getInfo(photo_id=photo.attrib['id'])
# http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{secret}.jpg
href = 'http://farm'+p[0].attrib['farm']+'.static.flickr.com/'+p[0].attrib['server']+'/'+p[0].attrib['id']+'_'+p[0].attrib['secret']+'.jpg'
request = urllib2.Request(href, None, {'User-Agent': useragent})
remotefile = urllib2.urlopen(request)
print 'downloading ' + href
localfile = open('dump/'+href.split('/')[-1], "wb")
localfile.write(remotefile.read())
localfile.close()
t_pool.append(photo.attrib['owner'])