import time
import os

#parameters
sunset_hr=8
dawn_hr=7
daytime_period_min=60
nighttime_period_min=1

time.localtime()
print("program starts at ",time.localtime());

while(1):

    #Is it day or night?
    time.localtime()
    hour = time.localtime()[3]
    minute = time.localtime()[4]
    hour_float = 1.0*hour+minute/60.0
    if( hour_float>(sunset_hr+12) or hour_float<dawn_hr ):
        daytime=0
    else :
        daytime=1
    print("Is it day? ",daytime)

    # night
    if( daytime==0): # night

        filename='sky-{:d}-{:02d}-{:02d}-{:02d}-{:02d}-{:02d}.jpg'.format(
            time.localtime()[0], # year
            time.localtime()[1], # month
            time.localtime()[2], # day of month
            time.localtime()[3], # hr
            time.localtime()[4], # min
            time.localtime()[5] # sec
        )

        path="/home/pi/skyphotos/data/night/"
        command = ("raspistill --shutter 30000000 --analoggain 12.0" +
                " --digitalgain 1.0 --nopreview --mode 3 "+
                " --annotate "+filename+" -o "+path+filename )
        print("running command: ",command)
        os.system(command)
        print("took picture ",filename)

        command = "rclone copy " +path+filename+ " wsu-physics-skycamera:23817_camera/night/ "
        os.system(command)
        print("uploaded picture ",filename)

        if(time.localtime()[3]>sunset_hr) :
            time.sleep(30*60) # wait 30 min if its before midnight
        # normal wait
        time.sleep(nighttime_period_min*60)

    # day
    if(daytime==1): #implicit else

        filename='sky-{:d}-{:02d}-{:02d}-{:02d}-{:02d}-{:02d}.jpg'.format(
            time.localtime()[0], # year
            time.localtime()[1], # month
            time.localtime()[2], # day of month
            time.localtime()[3], # hr
            time.localtime()[4], # min
            time.localtime()[5] # sec
        )

        path="/home/pi/skyphotos/data/day/"
        command="raspistill -annotate "+filename+" --nopreview --mode 3 -o " + path + filename
        os.system(command)
        print("took picture ",filename)

        command = "rclone copy " +path+filename+ " wsu-physics-skycamera:23817_camera/day/ "
        os.system(command)
        print("uploaded picture ",filename)

        time.sleep(daytime_period_min*60)

# program (never) ends

[((10, 0, 10, 16), 'time.localtime', 'time.localtime', ({}, {}), '()', False, 'import time\n'), ((11, 27, 11, 43), 'time.localtime', 'time.localtime', ({}, {}), '()', False, 'import time\n'), ((16, 4, 16, 20), 'time.localtime', 'time.localtime', ({}, {}), '()', False, 'import time\n'), ((17, 11, 17, 27), 'time.localtime', 'time.localtime', ({}, {}), '()', False, 'import time\n'), ((18, 13, 18, 29), 'time.localtime', 'time.localtime', ({}, {}), '()', False, 'import time\n'), ((43, 8, 43, 26), 'os.system', 'os.system', ({(43, 18, 43, 25): 'command'}, {}), '(command)', False, 'import os\n'), ((47, 8, 47, 26), 'os.system', 'os.system', ({(47, 18, 47, 25): 'command'}, {}), '(command)', False, 'import os\n'), ((53, 8, 53, 43), 'time.sleep', 'time.sleep', ({(53, 19, 53, 42): '(nighttime_period_min * 60)'}, {}), '(nighttime_period_min * 60)', False, 'import time\n'), ((69, 8, 69, 26), 'os.system', 'os.system', ({(69, 18, 69, 25): 'command'}, {}), '(command)', False, 'import os\n'), ((73, 8, 73, 26), 'os.system', 'os.system', ({(73, 18, 73, 25): 'command'}, {}), '(command)', False, 'import os\n'), ((76, 8, 76, 41), 'time.sleep', 'time.sleep', ({(76, 19, 76, 40): '(daytime_period_min * 60)'}, {}), '(daytime_period_min * 60)', False, 'import time\n'), ((51, 12, 51, 29), 'time.sleep', 'time.sleep', ({(51, 23, 51, 28): '(30 * 60)'}, {}), '(30 * 60)', False, 'import time\n'), ((30, 12, 30, 28), 'time.localtime', 'time.localtime', ({}, {}), '()', False, 'import time\n'), ((31, 12, 31, 28), 'time.localtime', 'time.localtime', ({}, {}), '()', False, 'import time\n'), ((32, 12, 32, 28), 'time.localtime', 'time.localtime', ({}, {}), '()', False, 'import time\n'), ((33, 12, 33, 28), 'time.localtime', 'time.localtime', ({}, {}), '()', False, 'import time\n'), ((34, 12, 34, 28), 'time.localtime', 'time.localtime', ({}, {}), '()', False, 'import time\n'), ((35, 12, 35, 28), 'time.localtime', 'time.localtime', ({}, {}), '()', False, 'import time\n'), ((50, 11, 50, 27), 'time.localtime', 'time.localtime', ({}, {}), '()', False, 'import time\n'), ((59, 12, 59, 28), 'time.localtime', 'time.localtime', ({}, {}), '()', False, 'import time\n'), ((60, 12, 60, 28), 'time.localtime', 'time.localtime', ({}, {}), '()', False, 'import time\n'), ((61, 12, 61, 28), 'time.localtime', 'time.localtime', ({}, {}), '()', False, 'import time\n'), ((62, 12, 62, 28), 'time.localtime', 'time.localtime', ({}, {}), '()', False, 'import time\n'), ((63, 12, 63, 28), 'time.localtime', 'time.localtime', ({}, {}), '()', False, 'import time\n'), ((64, 12, 64, 28), 'time.localtime', 'time.localtime', ({}, {}), '()', False, 'import time\n')]