Skip to content

Commit

Permalink
now loops over all sets instead of taking setid parameter
Browse files Browse the repository at this point in the history
photo title is now derived from photo set title.
tags are derived from photo title + exif data.
  • Loading branch information
davidthewatson committed Apr 9, 2012
1 parent 94b8e6d commit 4005aec
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
env
api.yaml
*.py~
30 changes: 19 additions & 11 deletions munge.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import yaml # easy_install pyyaml
import sys

def format_tags(tags):
def format_tags(tags, quotes=False):
output = ''
for tag in tags:
txtstr = ''
Expand All @@ -12,26 +12,34 @@ def format_tags(tags):
txtstr = z.text
elif z.tag in ('raw') and txtstr == '':
txtstr = z.text
output += '%s: %s\n' % (tagstr, txtstr)
if quotes:
output += '"%s: %s" ' % (tagstr, txtstr)
else:
output += '%s: %s\n' % (tagstr, txtstr)
return output

api = yaml.load(open('api.yaml'))
flickr = flickrapi.FlickrAPI(api['key'], api['secret'])
(token, frob) = flickr.get_token_part_one(perms='write')
if not token: raw_input("Press ENTER after you authorize this program")
flickr.get_token_part_two((token, frob))
set_title = flickr.photosets_getInfo(photoset_id=sys.argv[1])[0].getchildren()[0].text
this_set = flickr.walk_set(sys.argv[1])
tag_set = ('Aperture', 'FocalLength', 'Focal Length', 'ISO', 'ISOSpeed', 'ISO Speed', 'Make', 'Model', 'Exposure', 'ExposureTime', 'Exposure Time')
for photo in this_set:
set_list = flickr.photosets_getList()
for item in set_list[0]:
set_title = item[0].text
this_set = flickr.walk_set(item.attrib['id'])
print item.attrib['id']
tag_set = ('Aperture', 'FocalLength', 'Focal Length', 'ISO', 'ISOSpeed', 'ISO Speed', 'Make', 'Model', 'Exposure', 'ExposureTime', 'Exposure Time')
for photo in this_set:
photo_id = photo.get('id')
try:
exif = flickr.photos_getExif(photo_id=photo_id)
exif = flickr.photos_getExif(photo_id=photo_id)
except:
print 'exception on get exif'
continue
print 'exception on get exif'
continue
msg = ''
tags = set_title
for x in exif:
msg += format_tags(y for y in x if y.attrib['tag'] in tag_set or y.attrib['label'] in tag_set)
msg += 'Photograph by <a href="http://davidwatson.org/">David Watson</a>\r\nLicensed under <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons, Attribution, Non-Commercial, Share-Alike</a>\r\nYou may use this image on the internet with proper attribution and a link to my site.\r\n' + format_tags(y for y in x if y.attrib['tag'] in tag_set or y.attrib['label'] in tag_set)
tags += ' ' + format_tags((y for y in x if y.attrib['tag'] in tag_set or y.attrib['label'] in tag_set), True)
flickr.photos_setMeta(photo_id=photo_id, title=set_title, description=msg)
flickr.photos_addTags(photo_id=photo_id, tags=tags)
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PyYAML==3.10
flickrapi==1.4.2
wsgiref==0.1.2

0 comments on commit 4005aec

Please sign in to comment.