2 from suncalc
import get_position
, get_times
3 from datetime
import datetime
, timedelta
, date
9 #now = datetime(2023, 12, 13, 0, 0)
10 date
= now
.replace(hour
=12, minute
=0, second
=0, microsecond
=0)
16 sun
= get_times(date
, lon
, lat
, height
)
18 if type(sun
["nautical_dawn"]) is datetime
:
19 sunup
= sun
["nautical_dawn"] + timedelta(hours
=1)
22 if type(sun
["nautical_dusk"]) is datetime
:
23 sundown
= sun
["nautical_dusk"] + timedelta(hours
=1)
25 sundown
= now
+ timedelta(hours
=23, minutes
=59, seconds
=50)
27 # If sunup is in the future
29 countdown
= (sunup
- now
).total_seconds()
30 countdown_read
= sunup
- now
31 duration
= (sundown
- sunup
).total_seconds() * 1000
32 duration_read
= sundown
- sunup
36 duration
= (sundown
- now
).total_seconds() * 1000
37 duration_read
= sundown
- now
40 print("Sun already set, fool")
44 print(" Now is ", now
)
45 print(" Date is ", date
)
46 print(" Sun up is ", sunup
)
47 print(" Sun down is ", sundown
)
48 print("Countdown is ", countdown_read
)
49 print(" Duration is ", duration_read
)
52 print(int(countdown
), int(duration
), sep
='\t')