-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphotos_for_pool.py
executable file
·99 lines (80 loc) · 2.56 KB
/
photos_for_pool.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/python
"""Usage: python photos_for_pool.py [OPTIONS] group_id
group_id must the flickr NSID for a group
OPTIONS:
-v or --verbose
-e or --equal : width and height of photo must be the same
-s size or --size size : size of photo Thumbnail, Small,
Medium, Large, Original
-n number or --number number : the number of photos to retrieve
"""
__author__ = "James Clarke <[email protected]>"
__version__ = "$Rev$"
__date__ = "$Date$"
__copyright__ = "Copyright 2004-5 James Clarke"
import sys
import urllib
import flickr
verbose = False
def getURL(photo, size, equal=False):
"""Retrieves a url for the photo. (flickr.photos.getSizes)
photo - the photo
size - what size 'Thumbnail, Small, Medium, Large, Original'
equal - should width == height?
"""
method = 'flickr.photos.getSizes'
data = flickr._doget(method, photo_id=photo.id)
for psize in data.rsp.sizes.size:
if psize.label == size:
if equal and psize.width == psize.height:
return psize.source
elif not equal:
return psize.source
raise flickr.FlickrError, "No URL found"
def getPhotoURLs(groupid, size, number, equal=False):
group = flickr.Group(groupid)
photos = group.getPhotos(per_page=number)
urls = []
for photo in photos:
try:
urls.append(getURL(photo, size, equal))
except flickr.FlickrError:
if verbose:
print "%s has no URL for %s" % (photo, size)
return urls
def main(*argv):
from getopt import getopt, GetoptError
try:
(opts, args) = getopt(argv[1:],\
'ves:n:',\
['verbose', 'size', 'equal', 'number'])
except GetoptError, e:
print e
print __doc__
return 1
size = 'Medium'
equal = False
number = 100
for o, a in opts:
if o in ('-s' , '--size'):
size = a.capitalize()
elif o in ('-e', '--equal'):
equal = True
elif o in ('-v', '--verbose'):
verbose = True
elif o in ('-n', '--number'):
number = a
else:
print "Unknown argument: %s" % o
print __doc__
return 1
if len(args) == 0:
print "You must specify a group"
print __doc__
return 1
groupid = args[0]
urls = getPhotoURLs(groupid, size, number, equal)
for url in urls:
print url
if __name__ == '__main__':
sys.exit(main(*sys.argv))