def calc_sunrise(lat, lon, doy, date): date = date.replace(hour=0) sun = Sun() coords = {'longitude': lon, 'latitude': lat} sunr_dec = sun.getSunriseTime(coords, date=date)['decimal'] suns_dec = sun.getSunsetTime(coords, date=date)['decimal'] sunr_dec *= 60 suns_dec *= 60 sunrise = date + pd.to_timedelta(sunr_dec, unit='m') sunset = date + pd.to_timedelta(suns_dec, unit='m') return sunrise, sunset
print(x) return # This is the start of the main program coords = {'longitude': 0.34, 'latitude': 51.1} sun = Sun() print sun.getSunriseTime(coords) # Sunrise time UTC (decimal, 24 hour format) push("hi") print sun.getSunriseTime(coords)['hr'] print sun.getSunriseTime(coords)['min'] print sun.getSunsetTime(coords)['hr'] print sun.getSunsetTime(coords)['min'] GPIO.setmode(GPIO.BOARD) PIR_PIN = 26 GPIO.setup(PIR_PIN, GPIO.IN) print howfar() try: print("testing c to exit") sleep(2) print("ready") push("Testing") while True: if GPIO.input(PIR_PIN):
pass #update RCT time form network ntptime.host = 'pool.ntp.org' #ntptime.settime() now = float("{}.{}".format(localtime()[3], localtime()[4])) print("time: {}".format(localtime())) #calculate sunrise/sunset time coords = {'longitude': 2.107, 'latitude': 44.584} sun = Sun() # Sunrise time UTC (decimal, 24 hour format) sunrise = sun.getSunriseTime(coords)['decimal'] print("Sunrise (UTC decimal) : {}".format(sunrise)) # Sunset time UTC (decimal, 24 hour format) sunset = sun.getSunsetTime(coords)['decimal'] print("Sunset (UTC decimal): {}".format(sunset)) #scheduling stepPin = PWM(Pin(STEP_PIN), freq=0, duty=32) stopTim = Timer(1) dirPin = Pin(DIR_PIN, Pin.OUT) #override now variable for testing now = 7.45 #callback def closeDoor(_): dirPin.value(0)
def getSunsetTime(longitude, latitude): from sun import Sun coords = {'longitude': longitude, 'latitude': latitude} sun = Sun() sunset = sun.getSunsetTime(coords) return utc2local_time(sunset['hr'], sunset['min'])