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

[((103, 119), 'time.localtime', 'time.localtime', ([], {}), '()\n', (117, 119), False, 'import time\n'), ((147, 163), 'time.localtime', 'time.localtime', ([], {}), '()\n', (161, 163), False, 'import time\n'), ((207, 223), 'time.localtime', 'time.localtime', ([], {}), '()\n', (221, 223), False, 'import time\n'), ((235, 251), 'time.localtime', 'time.localtime', ([], {}), '()\n', (249, 251), False, 'import time\n'), ((268, 284), 'time.localtime', 'time.localtime', ([], {}), '()\n', (282, 284), False, 'import time\n'), ((1129, 1147), 'os.system', 'os.system', (['command'], {}), '(command)\n', (1138, 1147), False, 'import os\n'), ((1292, 1310), 'os.system', 'os.system', (['command'], {}), '(command)\n', (1301, 1310), False, 'import os\n'), ((1497, 1534), 'time.sleep', 'time.sleep', (['(nighttime_period_min * 60)'], {}), '(nighttime_period_min * 60)\n', (1507, 1534), False, 'import time\n'), ((2057, 2075), 'os.system', 'os.system', (['command'], {}), '(command)\n', (2066, 2075), False, 'import os\n'), ((2218, 2236), 'os.system', 'os.system', (['command'], {}), '(command)\n', (2227, 2236), False, 'import os\n'), ((2290, 2325), 'time.sleep', 'time.sleep', (['(daytime_period_min * 60)'], {}), '(daytime_period_min * 60)\n', (2300, 2325), False, 'import time\n'), ((1412, 1431), 'time.sleep', 'time.sleep', (['(30 * 60)'], {}), '(30 * 60)\n', (1422, 1431), False, 'import time\n'), ((595, 611), 'time.localtime', 'time.localtime', ([], {}), '()\n', (609, 611), False, 'import time\n'), ((635, 651), 'time.localtime', 'time.localtime', ([], {}), '()\n', (649, 651), False, 'import time\n'), ((676, 692), 'time.localtime', 'time.localtime', ([], {}), '()\n', (690, 692), False, 'import time\n'), ((724, 740), 'time.localtime', 'time.localtime', ([], {}), '()\n', (738, 740), False, 'import time\n'), ((762, 778), 'time.localtime', 'time.localtime', ([], {}), '()\n', (776, 778), False, 'import time\n'), ((801, 817), 'time.localtime', 'time.localtime', ([], {}), '()\n', (815, 817), False, 'import time\n'), ((1367, 1383), 'time.localtime', 'time.localtime', ([], {}), '()\n', (1381, 1383), False, 'import time\n'), ((1667, 1683), 'time.localtime', 'time.localtime', ([], {}), '()\n', (1681, 1683), False, 'import time\n'), ((1707, 1723), 'time.localtime', 'time.localtime', ([], {}), '()\n', (1721, 1723), False, 'import time\n'), ((1748, 1764), 'time.localtime', 'time.localtime', ([], {}), '()\n', (1762, 1764), False, 'import time\n'), ((1796, 1812), 'time.localtime', 'time.localtime', ([], {}), '()\n', (1810, 1812), False, 'import time\n'), ((1834, 1850), 'time.localtime', 'time.localtime', ([], {}), '()\n', (1848, 1850), False, 'import time\n'), ((1873, 1889), 'time.localtime', 'time.localtime', ([], {}), '()\n', (1887, 1889), False, 'import time\n')]