TheHatMan

PiLapse - Timelapse for the raspberry Pi

Nov 30th, 2013
2,731
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from datetime import datetime, date, time
  2. import os
  3. import time
  4.  
  5. #PiLapse, originally written by The HatMan
  6. #Note, all of the print lines can be commented out and are not necessary
  7.  
  8. #Sets time for when the photos are taken, default value is 0, 5, 10, 15, 20
  9. phot0 = 0
  10. phot1 = 5
  11. phot2 = 10
  12. phot3 = 15
  13. phot4 = 20
  14.  
  15. #sets time for when the renaming process is going to happen, default is one hour after
  16. ren0 = phot0+1
  17. ren1 = phot1+1
  18. ren2 = phot2+1
  19. ren3 = phot3+1
  20. ren4 = phot4+1
  21.  
  22. #used for testing the code
  23. test1 = 15
  24.  
  25.  
  26. #counts repeats of the while loop, can be commented out.
  27. counter = 0
  28.  
  29. print('To escape loop, use Ctrl+C')
  30. print()
  31.  
  32. while True is True:
  33.     YMD = date.today()
  34.     ymd = YMD.isoformat()
  35.     hour = datetime.now().hour
  36.     minute = datetime.now().minute
  37.  
  38.     #the lines below check if it is time for a photo, and uses the names photX and compares to the current hour, the os.path checks if a file is already created, to avoid duplicates
  39.     if(((hour == phot0 or hour == phot1 or hour == phot2 or hour == phot3 or hour == phot4) is True and (os.path.exists('current.jpg') is False)) is True):
  40.         #the call below calls for the camera module to take a picture, default name is current.jpg, commented out as the call does not work in a windows enviromnent
  41.         #call (['raspistill -o current.jpg -q 100 -w 1920 -h 1080'], shell=True)
  42.         print('image current.jpg taken')
  43.  
  44.     #the lines below check if it is time for renaming (default happens one hour after it takes the picture, as expressed by renX=photX+1
  45.     if(((hour == ren0 or hour == ren1 or hour == ren2 or hour == ren3 or hour == ren4) is True and (os.path.exists('current.jpg') is True)) is True):
  46.         os.rename('current.jpg', str(ymd)+'_'+str(int(hour)-1)+'.jpg')
  47.         print('renamed the file current.jpg')
  48.  
  49.     #pauses the software, the value inside of () signals the amount of seconds
  50.     time.sleep(2)
  51.    
  52.     #Use the below print() to signal that the software is moving forward during debug
  53.     #print(str(hour))
  54.     #print(str(minute))
  55.  
  56.     #Adds one to the counter, and shows the amount in the counter.s
  57.     counter = counter+1
  58.     print('Currently '+str(counter)+' returns done')
  59.     print()
RAW Paste Data