Эфем восход-1 минута - PullRequest
       22

Эфем восход-1 минута

0 голосов
/ 01 апреля 2019

Я пытаюсь заставить код работать за минуту до восхода солнца, но после обновления кода (через другой вопрос), так как я изменил часовые пояса с GMT, у меня возникают проблемы с правильным синтаксисом при удалении одной минуты.

sunriselessonemin = (ephem.date(sunrise)) + (1*ephem.minute)

Восход солнца получается

sunrise, sunset = ephem.localtime(home.next_rising(sun)),ephem.localtime(home.next_setting(sun))

Может кто-нибудь помочь нубу? Merci

Отредактировано, чтобы быть более понятным: -)

Вот мой оригинальный код. Raspberry Pi Я использую перезагрузки через Crontab в 4 утра, при запуске, этот скрипт запускается. В Великобритании все шло нормально, но сейчас я не в том часовом поясе, мне нужно было добавить местную работу в соответствии с предыдущим советом бренда.

import sys
import os
import time
import ephem

#find time of sun rise and sunset
sun = ephem.Sun()
home = ephem.Observer()
home.lat, home.lon = '45.226691', '0.013133' #your lat long 
sun.compute(home)
sunrise, sunset = ephem.localtime(home.next_rising(sun)),ephem.localtime(home.next_setting(sun))
daylightminutes = (sunset - sunrise) * 1440 # find howmany minutes of daylight there are
sunriselessonemin = ephem.date(sunrise + 1*ephem.minute)

print "prog started at(home.date) =  %s" %(home.date)
print "datetime = %s" % time.strftime("%Y/%-m/%-d %H:%M:%S")
print "sunrise = %s" %sunrise
print "sunset = %s" %sunset
print "daylight mins = %s" %(daylightminutes)

testmode = "yes" #yes or no

def dostuff() :
    if testmode == "yes" or sunrise <= ephem.now() <= sunriselessonemin: #if time now is within a minute of sunrise, start taking pictures
        print "it's sunrise!"
        if testmode == "yes" : 
            print "TESTMODE - Taking 10 images with 10 seconds in between and uploading made mp4 to Dropbox"
        FRAMES = daylightminutes # number of images you want in timelapse video
        if testmode == "yes" : 
            FRAMES = 10
        FPS_IN = 8 # number of images per second you want in video
        FPS_OUT = 8 # number of fps in finished video 24 is a good value
        TIMEBETWEEN = 60 # number of seconds between pictures, 60 = 1 minute
        #take the pictures needed for the time lapse video
        if testmode == "yes" : 
            TIMEBETWEEN = 10
        frameCount = 1
        while frameCount < (FRAMES + 1):
            print "taking image number ", frameCount, " of ", daylightminutes
            datetimenowis = ephem.now() 
            imageNumber = str(frameCount).zfill(7)
            os.system("raspistill -o /home/pi/image%s.jpg"%(imageNumber)) # -rot 270 need for cam on side (put -rot 270 before -o)
            os.system("/usr/bin/convert /home/pi/image%s.jpg -pointsize 72 -fill white -annotate +40+1590 'Chicken Cam %s' /home/pi/image%s.jpg"%(imageNumber,datetimenowis,imageNumber))
            frameCount += 1
            time.sleep(TIMEBETWEEN - 10) #Takes roughly 6 seconds to take a picture & 4 to add text to image
        #record current time and date in variable datetime
        datetimenowis = time.strftime("%Y%m%d-%H%M")
        print "It's sunset, processing images into one mp4 video.  Time now is ",  datetimenowis
        # make the timelapse video out of the images taken
        os.system("avconv -r %s -i /home/pi/image%s.jpg -r %s -vcodec libx264 -crf 20 -g 15 -vf crop=2592:1458,scale=1280:720 /home/pi/timelapse%s.mp4" %(FPS_IN,'%7d',FPS_OUT,datetimenowis))
        #send the timelapse video to dropbox
        print "Sending mp4 video to dropbox."
        from subprocess import call
        photofile = "/home/pi/Dropbox-Uploader/dropbox_uploader.sh upload /home/pi/timelapse%s.mp4 timelapse%s.mp4" %(datetimenowis,datetimenowis) 
        call ([photofile], shell=True)
        print "mp4 uploaded to dropbox!  Cleaning up."
        #remove the timelapse video copy and all images it is made up of that are held localy on the Rpi
        os.system("rm /home/pi/timelapse%s.mp4"%(datetimenowis))
        os.system("rm /home/pi/image*")
        print "Finished, exiting program."
        sys.exit()

while ephem.now() <= sunrise:
        time.sleep(1)
        dostuff()

Проблема в momnet заключается в том, что, если я попытаюсь переписать основной код за одну минуту до заката. код здесь не работает.

    pi@raspberrypi ~ $ sudo python timelapseV3.py
Traceback (most recent call last):
  File "timelapseV3.py", line 13, in <module>
    sunriselessonemin = ephem.date(sunrise + 1*ephem.minute)
TypeError: unsupported operand type(s) for +: 'datetime.datetime' and 
'float'

Кажется, я не могу запустить код за минуту до восхода солнца, как раньше.

ура

...