個人的なプロジェクトのために 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)