From 2aad40a3b57a1324f7328c6d8547d6372af5eefe Mon Sep 17 00:00:00 2001 From: =?utf8?q?Einar=20J=C3=B8rgen=20Haraldseid?= Date: Wed, 13 Dec 2023 18:49:06 +0100 Subject: [PATCH 1/1] =?utf8?q?Script=20for=20=C3=A5=20beregne=20soloppgang?= =?utf8?q?=20og=20solnedgang,=20til=20bruk=20med=20raspistill?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- sun.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 sun.py 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') -- 2.30.2