#!/usr/bin/ # Rough script to MOVE files to dropbox from a timelapse dump # Assumes pi-timolo is used to generate images # Copies latest file to fixed filename import glob import os import subprocess import re thedir="/home/pi/pi-timolo/timelapse/*.jpg" uploadCmd="/home/pi/dropbox-uploader.sh" print "Using %s"%uploadCmd dest="Public/BeesonRpiCam/" FNULL = open(os.devnull, 'w') timoloNumberFile="/home/pi/pi-timolo/tl-pi-timolo.dat" for fn in sorted(glob.iglob(thedir)): try: with open(timoloNumberFile) as myfile: currentNum=myfile.read() myfile.close() matchObj= re.match(r'.*'+currentNum+r'\.jpg$',fn) if matchObj: print("Last number is %s"%currentNum) print("Skipping as match on %s"%fn) else: dname, bname = os.path.split(fn) print ("Uploading " + fn) ret = subprocess.check_call([uploadCmd, "upload",fn,dest]) #,stderr=FNULL,stdout=FNULL) print("Copying latest from " + dest+bname) ret = subprocess.call([uploadCmd, "delete",dest+"0-latest.jpg"]) #,stderr=FNULL,stdout=FNULL) ret = subprocess.check_call([uploadCmd, "copy",dest+bname,dest+"0-latest.jpg"]) #,stderr=FNULL,stdout=FNULL) os.unlink(fn) print ("Done with %s"%fn) except subprocess.CalledProcessError: print ("Failed on calling upload script for " + fn) except Exception: print ("Unexpected error:", sys.exc_info()[0])