From: Einar Jørgen Haraldseid Date: Wed, 13 Dec 2023 17:49:06 +0000 (+0100) Subject: Script for å beregne soloppgang og solnedgang, til bruk med raspistill X-Git-Url: https://git.slaskete.net/einar-bin/commitdiff_plain/2aad40a3b57a1324f7328c6d8547d6372af5eefe?hp=e3f52b30f6c8b191aa48647a5ee1e46f52e6d386 Script for å beregne soloppgang og solnedgang, til bruk med raspistill --- diff --git a/sun.py b/sun.py new file mode 100644 index 0000000..c46cc67 --- /dev/null +++ b/sun.py @@ -0,0 +1,52 @@ +#!/usr/bin/python3 +from suncalc import get_position, get_times +from datetime import datetime, timedelta, date + +debug = False +#debug = True + +now = datetime.now() +#now = datetime(2023, 12, 13, 0, 0) +date = now.replace(hour=12, minute=0, second=0, microsecond=0) + +lon = 10.71 +lat = 60.772 +height = 100 + +sun = get_times(date, lon, lat, height) + +if type(sun["nautical_dawn"]) is datetime: + sunup = sun["nautical_dawn"] + timedelta(hours=1) +else: + sunup = now +if type(sun["nautical_dusk"]) is datetime: + sundown = sun["nautical_dusk"] + timedelta(hours=1) +else: + sundown = now + timedelta(hours=23, minutes=59, seconds=50) + +# If sunup is in the future +if now < sunup: + countdown = (sunup - now).total_seconds() + countdown_read = sunup - now + duration = (sundown - sunup).total_seconds() * 1000 + duration_read = sundown - sunup +else: + countdown = 0 + countdown_read = 0 + duration = (sundown - now).total_seconds() * 1000 + duration_read = sundown - now + +if int(duration) < 0: + print("Sun already set, fool") + exit(1) + +if debug: + print(" Now is ", now) + print(" Date is ", date) + print(" Sun up is ", sunup) + print(" Sun down is ", sundown) + print("Countdown is ", countdown_read) + print(" Duration is ", duration_read) + print("") + +print(int(countdown), int(duration), sep='\t')