Fix up the new-photo-post script

Make the script a little more resilient. Print out some EXIF data that the template
will use when generating the page.

Update the photostream submodule commit.

Remove the unused photo_exif_table.html partial.
This commit is contained in:
Eryn Wells 2024-11-04 08:37:17 -08:00
parent 602f5fa26c
commit 0cef7a7903
3 changed files with 33 additions and 72 deletions

View file

@ -7,12 +7,14 @@ New script.
import argparse
import datetime
import json
import os.path
import re
import shutil
import subprocess
from PIL import Image
from PIL.ExifTags import TAGS
from typing import Optional
PHOTOS_CONTENT_DIR = 'content/photos'
@ -24,6 +26,7 @@ def parse_args(argv, *a, **kw):
parser.add_argument('-n', '--dry-run', action='store_true')
parser.add_argument('-t', '--title')
parser.add_argument('-s', '--slug')
parser.add_argument('--dump-exif', action='store_true')
parser.add_argument('photos', nargs='+')
args = parser.parse_args(argv)
return args
@ -31,9 +34,11 @@ def parse_args(argv, *a, **kw):
def main(argv):
args = parse_args(argv[1:], prog=argv[0])
earliest_exif_date = None
earliest_exif_date: Optional[datetime.datetime] = None
for index, photo in enumerate(args.photos):
print(f'image\t\t{photo}')
for photo in args.photos:
try:
image = Image.open(photo)
except IOError:
@ -47,12 +52,34 @@ def main(argv):
exif_date = datetime.datetime.strptime(date_string, '%Y:%m:%d %H:%M:%S %z')
except KeyError:
exif_date = datetime.datetime.strptime(friendly_exif["DateTime"], '%Y:%m:%d %H:%M:%S')
print(f'capture-time\t{exif_date.isoformat()}')
print(f'{photo} -> {exif_date.isoformat()}')
iso_rating = friendly_exif.get('ISOSpeedRatings')
if iso_rating:
print(f'iso\t\t{iso_rating}')
focal_length_35mm = friendly_exif.get('FocalLengthIn35mmFilm')
focal_length = friendly_exif.get('FocalLength')
if focal_length or focal_length_35mm:
print(f'focal-length\t{focal_length} {focal_length_35mm}')
fstop = friendly_exif.get('FNumber')
if fstop:
print(f'f-stop\t\t{fstop}')
exposure_time = friendly_exif.get('ExposureTime')
if exposure_time:
print(f'exposure-time\t{exposure_time}')
if not earliest_exif_date or exif_date < earliest_exif_date:
earliest_exif_date = exif_date
if index < len(args.photos) - 1:
print()
if not earliest_exif_date:
earliest_exif_date = datetime.datetime.now()
year = earliest_exif_date.year
month = earliest_exif_date.month
@ -83,12 +110,12 @@ def main(argv):
result = subprocess.run(hugo_command)
result.check_returncode()
else:
print(' '.join(hugo_command))
print(' '.join(hugo_command), file=sys.stderr)
except subprocess.CalledProcessError:
print(f'Failed to create new Hugo post', file=sys.stderr)
return -1
if args.title:
if args.title and not args.dry_run:
# The hugo command can't set a title for a post so I need to do it myself.
index_file_path = os.path.join(post_path, 'index.md')
with open(index_file_path) as index_file: