1

I just started Python3 scripting for a personal project. It is a timelaps computer that will make a timelaps of the sunrise every morning. I have copied a script for youtube and thats works. I like to add a part that the script is executed between times, so start at 06:00:00 to 07:00:00. If this works I can run another script (for making the video from the images or posting the video online) at another time, etc.

This is the original script:

while True:
   createSaveFolder()
   captureImages()
   renameImages(picID)

And i found this online, but it doesn't work....:

while ["$(datetime +"%T")" > '06:00:00' -a "$(datetime +"%T")" < '07:00:00']] :

What is the correct script (while statement) to use?

This is the whole script:

from time import sleep
from datetime import datetime
from sh import gphoto2 as gp
import signal, os, subprocess, time

# Kill process that starts when camera is connected

def killgphoto2Process():
   p = subprocess.Popen(['ps', '-A'], stdout=subprocess.PIPE)
   out, err = p.communicate()

   # Search for the line that has the prosess we want to kill
   for line in out.splitlines():
       if b'gvfsd-gphoto2' in line:
           # Kill the process!
           pid = int(line.split(None,1)[0])
           os.kill(pid, signal.SIGKILL)


shot_date = datetime.now().strftime("%Y-%m-%d")
shot_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
picID = "timelaps"


clearCommand = ["--folder","/store_00020001/DCIM/101MSDCF", \
               "-R", "--delete-all-files"]
triggerCommand = ["--trigger-capture"]
downloadCommand = ["--get-all-files"]


folder_name = shot_date = picID
save_location = "/home/pi/Desktop/gphoto/images/" + folder_name

def createSaveFolder():
   try:
       os.makedirs(save_location)
   except:
       print("Failed to create Dir")
   os.chdir(save_location)

def captureImages():
   gp(triggerCommand)
   sleep(3)
   gp(downloadCommand)
   gp(clearCommand)

def renameImages(ID):
   for filename in os.listdir("."):
       count = 0
       if len(filename) < 13:
           if filename.endswith(".JPG"):
               os.rename(filename, (shot_time + ID +".JPG"))
               print ("Renamed the JPG")
           elif filename.endswith(".CR2"):
               os.rename(filename, (shot_time + ID +".CR2"))
               print ("Renamed the CR2")

killgphoto2Process()
gp(clearCommand)

while True:
   createSaveFolder()
   captureImages()
   renameImages(picID)
Sebas
  • 11
  • 1

0 Answers0