--- /dev/null
+#!/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
+
+# OK - so we'll name the "album" by the directory name, and that'll be that.
+# The albums are just going to be straight imports of the directories for now
+
+root, dirs, files = os.walk("../media/photos/").next()
+
+for dir in dirs:
+ if Album.objects.filter(slug__exact=dir):
+ print "Already have a %s album, not importing" %(dir,)
+ else:
+ album = Album()
+ album.slug = dir
+ album.name = dir
+ if os.path.exists("../media/photos/%s/description.txt" %(dir)):
+ album.caption = open("../media/photos/%s/description.txt" %(dir)).read()
+ album.save()
+ captions = {}
+ if os.path.exists("../media/photos/%s/captions.txt" %(dir)):
+ capfh = open("../media/photos/%s/captions.txt" %(dir))
+ line = capfh.readline()
+ while line:
+ fname, value = line.split("\t", 1)
+ captions[fname] = value
+ line = capfh.readline()
+ for file in os.walk("../media/photos/%s/" %(dir)).next()[2]:
+ if file[-4:] == ".jpg":
+ photo = Photo()
+ photo.album = album
+ try:
+ photo.caption = captions[file]
+ except:
+ pass
+ photo.image = "photos/%s/%s" %(dir, file)
+ photo.save()