1

我刚刚开始为个人项目编写 Python3 脚本。这是一台时间间隔计算机,每天早上都会对日出进行时间间隔。我已经为 youtube 复制了一个脚本,这很有效。我喜欢添加脚本在时间之间执行的部分,所以从 06:00:00 到 07:00:00 开始。如果这可行,我可以在其他时间运行另一个脚本(用于从图像制作视频或在线发布视频)等。

这是原始脚本:

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

我在网上找到了这个,但它不起作用....:

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

要使用的正确脚本(while 语句)是什么?

这是整个脚本:

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)
4

0 回答 0