PiCamera 和 Schedule 不能一起工作

PiCamera and Schedule is not working together

我是编程的新手 python 并且不知道我做错了什么。我正在阅读 PiCamera 和 Schedule 的文档,但组合命令不起作用。

所以我想按照时间表进行:

schedule.every().day.at("17:20:30").do(Foto).until("17:21:30")

当作业是:print.("bla")

我想用 PiCamera 做到这一点:

camera = PiCamera()
camera.start_preview()
sleep(2)
for filename in camera.capture_continuous('img{counter:03d}.jpg'):
    print('Captured %s' % filename)
    sleep(300) # wait 5 minutes

这在它自己的脚本中也有效。 (由文档复制)

但是当我把它们放在一起时:

from picamera import PiCamera
from time import sleep
import schedule


def Foto():
camera = PiCamera() 
camera.start_preview()
sleep(2)
for filename in camera.capture_continuous('img{counter:03d}.jpg'):
    print('Captured %s' % filename)
    sleep(5) # wait 5 Sek

    
schedule.every().day.at("17:20:00").do(Foto).until("17:21:00")

while True:
    schedule.run_pending()
    time.sleep(1)

我收到一个错误:

Traceback (moste recent call last):
File "usr/lib/python3.9/ast.py", line 50, in parse
return compile(source, filename, mode, flags,
File "home/pi/Dokumente/Schedule.py", line 9
camera = PiCamera()
^
IndentationError: expected an indented block

我还尝试将 camera = PiCamera() 放在 import schedule 之前,这导致了这个错误:

Traceback (most recent call last):
  File "/usr/lib/python3.9/ast.py", line 50, in parse
    return compile(source, filename, mode, flags,
  File "/home/pi/Dokumente/Schedule.py", line 11
    camera.start_preview()
    ^
IndentationError: expected an indented block

希望你能帮助我:)

Ps。这是两个文档:

https://schedule.readthedocs.io/en/stable/examples.html#run-a-job-until-a-certain-time

https://picamera.readthedocs.io/en/release-1.13/recipes1.html#capturing-timelapse-sequences

Foto函数的代码没有缩进

def Foto():
    camera = PiCamera() 
    camera.start_preview()
    sleep(2)
    for filename in camera.capture_continuous('img{counter:03d}.jpg'):
        print('Captured %s' % filename)
        sleep(5) # wait 5 Sek