#small example program to print out IPTC data from a file import sys import iptcdata try: f = iptcdata.open(sys.argv[1]) except IndexError: print "show_iptc.py filename" if (len(f.datasets) == 0): print "No IPTC data!" sys.exit(0) for ds in f.datasets: print "Tag: %d\nRecord: %d" % (ds.record, ds.tag) print "Title: %s" % (ds.title) descr = iptcdata.get_tag_description(record=ds.record, tag=ds.tag) print "Description: %s" % (descr) print "Value: %s" % (ds.value) print f.close()
"--tags", dest="tags", action="store", type="string", help="Tags") parser.add_option("-T", "--title", dest="title", action="store", type="string", help="Title for photo") (options, args) = parser.parse_args() try: f = iptcdata.open(args[0]) except IndexError: print usage sys.exit(1) # first do the "title" which flickr wants as a "headline" if (options.title): # we want to replace this record set if it is there print "Setting \'Headline\' to %s" % (options.title) rs = iptcdata.find_record_by_name("Headline") ds = check_for_dataset(f, rs) if (ds == None): ds = f.add_dataset(rs) ds.value = options.title # a "caption" gives the caption
usage = "set_iptc.py [-c caption] [-t tag,tag,...] [-T title] filename" parser = OptionParser(usage, version="0.1") parser.add_option("-c", "--caption", dest="caption", action="store", type="string", help="Caption data for photo") parser.add_option("-t", "--tags", dest="tags", action="store", type="string", help="Tags") parser.add_option("-T", "--title", dest="title", action="store", type="string", help="Title for photo") (options, args) = parser.parse_args() try: f = iptcdata.open(args[0]) except IndexError: print usage sys.exit(1) # first do the "title" which flickr wants as a "headline" if (options.title): # we want to replace this record set if it is there print "Setting \'Headline\' to %s" % (options.title) rs = iptcdata.find_record_by_name("Headline") ds = check_for_dataset(f, rs) if (ds == None): ds = f.add_dataset(rs) ds.value = options.title # a "caption" gives the caption