#!/bin/python # Pull photos off my digital camera and stick them in the right directory, # timestamped and numbered. # Originally written for my L'Espion using gphoto, and modified for # my new camera's SmartMedia card which can be directly mounted. import sys, os, time images_dir = "/home/azz/Work/photos" temp_dir = "/tmp/camera" def command(cmd): if os.system(cmd) != 0: raise "Command failed: " + cmd def acquire_into(dir): try: os.mkdir(temp_dir) except: pass #os.chdir(dir) #command("gphoto2 -P") command("cp /media/sm/dcim/100_fuji/* " + dir) def clear_camera(): #command("gphoto2 -D") command("rm /media/sm/dcim/100_fuji/*") def convert_dir(dir): os.chdir(dir) for f in os.listdir(dir): if f[:5] == "image" and f[-4:] == ".pnm": # Espion pictures num = int(f[5:-4]) isjpeg = 0 elif f.upper()[:4] == "DSCF" and f.upper()[-4:] == ".JPG": # Fuji pictures num = int(f[4:-4]) isjpeg = 1 else: raise "Unparsable filename " + f mtime = time.gmtime(os.stat(dir + "/" + f).st_mtime) outdir = "%s/%s" % (images_dir, time.strftime("%Y%m%d")) try: os.mkdir(outdir) except OSError: pass outname = "%s/photo-%s-%03d.jpeg" % (outdir, time.strftime("%Y%m%dT%H%M%S", mtime), num) print "Writing " + outname + "...", if isjpeg: command("cp " + f + " " + outname) else: command("ppmtojpeg -q 85 <" + f + " >" + outname) print "OK" os.remove(dir + "/" + f) if __name__ == "__main__": command("mount /media/sm") acquire_into(temp_dir) convert_dir(temp_dir) clear_camera() command("umount /media/sm")