Skip to content

Commit d6cd38e

Browse files
committed
moves file naming logic out of main function
1 parent 013e63d commit d6cd38e

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

flickr_download/flick_download.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ def _load_defaults():
7777
return {}
7878

7979

80+
def get_filename(pset, photo, suffix):
81+
"""
82+
Create the filename to use for a given photo.
83+
84+
@param pset: Flickr.Photoset, the photoset
85+
@param photo: Flickr.Photo, the photo
86+
@param suffice: str, optional suffix
87+
@return: str, the filename
88+
"""
89+
return '{0}{1}.jpg'.format(photo.title, suffix)
90+
91+
8092
def download_set(set_id, size_label=None):
8193
"""
8294
Download the set with 'set_id' to the current directory.
@@ -100,8 +112,9 @@ def download_set(set_id, size_label=None):
100112

101113
if not os.path.exists(pset.title):
102114
os.mkdir(pset.title)
115+
103116
for photo in photos:
104-
fname = '{0}/{1}{2}.jpg'.format(pset.title, photo.title, suffix)
117+
fname = '{0}/{1}'.format(pset.title, get_filename(pset, photo, suffix))
105118
if os.path.exists(fname):
106119
# TODO: Ideally we should check for file size / md5 here
107120
# to handle failed downloads.

0 commit comments

Comments
 (0)