Python 3.x 如果为True:=>;启动和停止时间脚本

Python 3.x 如果为True:=>;启动和停止时间脚本,python-3.x,while-loop,timelapse,Python 3.x,While Loop,Timelapse,我刚刚开始为一个个人项目编写Python3脚本。这是一台timelaps电脑,每天早上都会对日出进行timelaps。我为youtube复制了一个脚本,效果不错。我想添加一个脚本在不同时间执行的部分,所以从06:00:00到07:00:00开始。 如果可以,我可以在其他时间运行另一个脚本(用于从图像制作视频或在线发布视频),等等 这是原始脚本: while True: createSaveFolder() captureImages() renameImages(picID)

我刚刚开始为一个个人项目编写Python3脚本。这是一台timelaps电脑,每天早上都会对日出进行timelaps。我为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']] :
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)
我在网上找到了这个,但它不起作用:

while True:
   createSaveFolder()
   captureImages()
   renameImages(picID)
while ["$(datetime +"%T")" > '06:00:00' -a "$(datetime +"%T")" < '07:00:00']] :
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)
while[“$(datetime+%T”)”>06:00:00'-a“$(datetime+%T”)”<'07:00:00']:
要使用的正确脚本(while语句)是什么

这是整个脚本:

while True:
   createSaveFolder()
   captureImages()
   renameImages(picID)
while ["$(datetime +"%T")" > '06:00:00' -a "$(datetime +"%T")" < '07:00:00']] :
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)
从时间导入睡眠
从日期时间导入日期时间
从sh导入gphoto2作为gp
导入信号、操作系统、子进程、时间
#连接相机时启动的终止进程
def killgphoto2Process():
p=subprocess.Popen(['ps','-A'],stdout=subprocess.PIPE)
out,err=p.communicate()
#搜索有我们想要杀死的过程的线
对于line in out.splitlines():
如果b'gvfsd-gphoto2'在线:
#结束这个过程!
pid=int(行分割(无,1)[0])
os.kill(pid,signal.SIGKILL)
shot\u date=datetime.now().strftime(“%Y-%m-%d”)
shot\u time=datetime.now().strftime(“%Y-%m-%d%H:%m:%S”)
picID=“timelaps”
clearCommand=[“--folder”、“/store_00020001/DCIM/101MSDCF”\
“-R”,“--删除所有文件”]
triggerCommand=[“--trigger capture”]
downloadCommand=[“--获取所有文件”]
文件夹名称=快照日期=picID
保存位置=“/home/pi/Desktop/gphoto/images/”+文件夹名称
def createSaveFolder():
尝试:
os.makedirs(保存位置)
除:
打印(“无法创建目录”)
os.chdir(保存位置)
def captureImages():
总工程师(触发命令)
睡眠(3)
gp(下载命令)
gp(clearCommand)
def重命名图像(ID):
对于os.listdir(“.”)中的文件名:
计数=0
如果len(文件名)<13:
如果filename.endswith(“.JPG”):
重命名(文件名,(shot_time+ID+“.JPG”))
打印(“重命名为JPG”)
elif filename.endswith(“.CR2”):
重命名(文件名,(shot_time+ID+“.CR2”))
打印(“重命名为CR2”)
killgphoto2Process()
gp(clearCommand)
尽管如此:
createSaveFolder()
captureImages()
重命名图像(picID)

您找到的东西似乎不是Python……嗯,好吧。。。我总是出错。你有一个解决方案可以一次开始,一次停止吗?然后阅读并给出一个答案。你发现的东西似乎不是Python…嗯,好吧。。。我总是出错。你有一个解决办法,一次开始,一次停止吗?然后阅读并给出一个答案。