]> git.sommitrealweird.co.uk Git - sommitrealweird.git/blob - scripts/update-photos.py
Make it so that we don't do anything silly in the context processor by trying
[sommitrealweird.git] / scripts / update-photos.py
1 #!/usr/bin/python
2
3 import sys
4 import os
5
6 os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
7
8 sys.path.append("../sommitrealweird")
9
10 from django.conf import settings
11 from photo.models import Album, Photo
12
13 def usage():
14     print "You must specify a photo album to update."
15
16 # check if we have an argument for the album name
17 if len(sys.argv) < 2:
18     usage()
19     sys.exit(2)
20
21 alb_slug = sys.argv[1]
22
23 # check if the album exists...
24 if not Album.objects.filter(slug__exact=alb_slug):
25     # there's no album, can't update.
26     print "Can't find album '%s'" %(alb_slug)
27
28 album = Album.objects.get(slug__exact=alb_slug)
29
30 # loop through photos, carefully
31 root, dirs, files = os.walk("../media/photos/%s" %(alb_slug)).next()
32 for file in files:
33     if not Photo.objects.filter(image__exact="photos/%s/%s" %(alb_slug, file)):
34         if file[-4:] == ".jpg":
35             photo = Photo()
36             photo.album = album
37             photo.image = "photos/%s/%s" %(alb_slug, file)
38             photo.save()
39