From 098711c34dbb5f0314f11a999f2e1bb3ddbf7461 Mon Sep 17 00:00:00 2001 From: Brett Parker Date: Sun, 8 Nov 2009 19:27:55 +0000 Subject: [PATCH] Script to update an album with files added at the filesystem level --- scripts/update-photos.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 scripts/update-photos.py diff --git a/scripts/update-photos.py b/scripts/update-photos.py new file mode 100644 index 0000000..78bef0b --- /dev/null +++ b/scripts/update-photos.py @@ -0,0 +1,39 @@ +#!/usr/bin/python + +import sys +import os + +os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' + +sys.path.append("../sommitrealweird") + +from django.conf import settings +from photo.models import Album, Photo + +def usage(): + print "You must specify a photo album to update." + +# check if we have an argument for the album name +if len(sys.argv) < 2: + usage() + sys.exit(2) + +alb_slug = sys.argv[1] + +# check if the album exists... +if not Album.objects.filter(slug__exact=alb_slug): + # there's no album, can't update. + print "Can't find album '%s'" %(alb_slug) + +album = Album.objects.get(slug__exact=alb_slug) + +# loop through photos, carefully +root, dirs, files = os.walk("../media/photos/%s" %(alb_slug)).next() +for file in files: + if not Photo.objects.filter(image__exact="photos/%s/%s" %(alb_slug, file)): + if file[-4:] == ".jpg": + photo = Photo() + photo.album = album + photo.image = "photos/%s/%s" %(alb_slug, file) + photo.save() + -- 2.39.5