#! /usr/bin/env python # coding: utf-8 """ Usage: cat descrip | ./make_individual_html.py Examines the descrip file and builds a medium, large and full size HTML page for each image, with forward, up, and back links on each page. descrip looks like: 100_2455 h Driving down Miller Hill 100_2549 v Storage shed next to the red cabin Sizes: _thumb 150 x 200 _med 600 x 800 _lg 900 x 1200 .jpg 1524 x 2032 This script Copyright © 2007, Christopher Swingley, and licensed under the terms of the GNU General Public License v3.0. Use at your own risk. """ import sys data = [] for line in sys.stdin.xreadlines(): line = line.strip() fields = line.split() image_base, orientation = fields[:2] descrip = ' '.join(fields[2:]) data.append((image_base, orientation, descrip)) def build_link_string(i, size_str): if size_str == 'full': if i == 0: links = '|| ^^ >>' % (data[i+1][0]) elif i == len(data) - 1: links = '<< ^^ ||' % (data[i-1][0]) else: links = '<< ^^ >>' % (data[i-1][0], data[i+1][0]) else: if i == 0: links = '|| ^^ >>' % (data[i+1][0], size_str) elif i == len(data) - 1: links = '<< ^^ ||' % (data[i-1][0], size_str) else: links = '<< ^^ >>' % (data[i-1][0], size_str, data[i+1][0], size_str) return links def build_image_string(image_base, orientation, size_str): sizes = {'med':(600, 800), 'lg':(900, 1200), 'full':(1524, 2032)} if orientation == 'v': image_size_str = 'height="%s" width="%s"' % (sizes[size_str][1], sizes[size_str][0]) else: image_size_str = 'height="%s" width="%s"' % (sizes[size_str][0], sizes[size_str][1]) if size_str == 'full': image_string = '' % (image_base, image_size_str) else: image_string = '' % (image_base, size_str, image_size_str) return image_string for i in range(len(data)): # for i in range(2): html_header_string = '\n\n\n' (image_base, orientation, descrip) = data[i] print "Making %s_med.html" % (image_base) ofl = open("%s_med.html" % (image_base), 'w') links = build_link_string(i, "med") image_string = build_image_string(image_base, orientation, "med") ofl.write('%s

%s

%s
%s
%s

' % (html_header_string, descrip, links, image_string, links)) ofl.close() print "Making %s_lg.html" % (image_base) ofl = open("%s_lg.html" % (image_base), 'w') links = build_link_string(i, "lg") image_string = build_image_string(image_base, orientation, "lg") ofl.write('%s

%s

%s
%s
%s

' % (html_header_string, descrip, links, image_string, links)) ofl.close() print "Making %s.html" % (image_base) ofl = open("%s.html" % (image_base), 'w') links = build_link_string(i, "full") image_string = build_image_string(image_base, orientation, "full") ofl.write('%s

%s

%s
%s
%s

' % (html_header_string, descrip, links, image_string, links)) ofl.close()