而真:=>启动停止时间脚本

时间:2016-11-13 21:07:36

标签: python-3.x while-loop timelapse

我刚刚为个人项目启动了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)

0 个答案:

没有答案
相关问题