#!/usr/bin/perl use strict; (print <<"EOH"), exit if grep { $_ eq '-h' } @ARGV; USAGE make_upload.prl ... DESCRIPTION Pass one or more dates. Reads captions.txt for each date, looks for photos marked to be uploaded to flickr, looks up the corresponding observation in notes and dumps out all the info, one per line. FILES Writes result to '../notes/upload.not'. Also writes a script to 'x' to resize and copy images into './upload'. NOTE Only lists info for first observation that uses a given photo! OPTIONS -h Print this message -f Force it to overwrite 'x' and 'upload.not'. EOH ################################################################################ my $OPT_F = 1 if grep { $_ eq '-f' } @ARGV; @ARGV = grep { $_ ne '-f' } @ARGV; mkdir 0775, 'upload' if !-d 'upload'; die "File 'upload.not' already exists!\n" if !$OPT_F && -e '../notes/upload.not'; die "Script 'x' already exists!\n" if !$OPT_F && -e 'x'; die "Upload directory isn't empty!\n" if !$OPT_F && glob('upload/*.jpg'); die "Upload directory doesn't exist!\n" if !-d 'upload'; foreach my $file (glob 'upload/*.jpg') { unlink $file; } open(my $out1, '>../notes/upload.not'); open(my $out2, '>x'); print $out1 "# vim:ts=40\n"; my $count = 0; foreach my $date (@ARGV) { my $file = "$date/captions.txt"; open(my $fh, "<$file"); while (<$fh>) { if (/^(\d+)!\s+(.*)/) { my ($photo, $caption) = ($1, $2); my $file = "/home/jason/public_html/born/notes/$date.not"; open(my $fh, "<$file") || die "Couldn't open $file: $!\n"; my $name = '.'; $photo += 0; while (<$fh>) { if (/^=(\d+\s+)? (\S[^[({]+\S) \s+\[.* PH="? (\d(?:[\d\-,]*\d)?)/x) { my ($num, $name2, $photos) = ($1, $2, $3); while ($photos =~ s/^(\d+)(?:-(\d+))?,?//) { if ($2 ? ($1 <= $photo && $2 >= $photo) : ($1 == $photo)) { $name = "=$num$name2"; last; } } } } close($fh); printf $out1 "%s\t(%08d-%03d %s)\n", $name, $date, $photo, $caption; printf $out2 "echo $date-%03d.jpg; convert -resize '1000000@>' $date/$photo.jpg upload/$date-%03d.jpg\n", $photo, $photo; $count++; } } close($fh); } close($out1); close($out2); print "Found $count images to upload.\n"; exit 0;