48 lines
1.5 KiB
Python
Executable file
48 lines
1.5 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
# Copyright © 2022 Daniele Tricoli <eriol@mornie.org>
|
|
#
|
|
# This program is free software. It comes without any warranty, to
|
|
# the extent permitted by applicable law. You can redistribute it
|
|
# and/or modify it under the terms of the Do What The Fuck You Want
|
|
# To Public License, Version 2, as published by Sam Hocevar.
|
|
# See http://www.wtfpl.net/ for more details.
|
|
|
|
"""
|
|
Get the difference in seconds between yesterday and today sunset at Rome.
|
|
|
|
An ugly example written fast and in one go to reply to this toot¹ by
|
|
@octo@mastodon.uno.
|
|
|
|
Date: 2022-11-29 19:03:37+01:00
|
|
|
|
¹ https://mastodon.uno/@octo/109427928198217919
|
|
"""
|
|
|
|
import datetime
|
|
from datetime import date
|
|
|
|
from astroplan import Observer
|
|
from astropy.time import Time
|
|
|
|
today = datetime.datetime.combine(
|
|
datetime.datetime.today(), datetime.time(hour=12, minute=30)
|
|
)
|
|
yesterday = today - datetime.timedelta(days=1)
|
|
|
|
o = Observer(longitude=12.496, latitude=41.902, name="Rome")
|
|
|
|
today_sun_set = o.sun_set_time(Time(today), which="next")
|
|
yesterday_sun_set = o.sun_set_time(Time(yesterday), which="next")
|
|
|
|
today_sun_set_time = datetime.datetime.combine(
|
|
date.min, today_sun_set.to_datetime().time()
|
|
)
|
|
yesterday_sun_set_time = datetime.datetime.combine(
|
|
date.min, yesterday_sun_set.to_datetime().time()
|
|
)
|
|
|
|
# This is fine only when yesterday_sun_set_time > today_sun_set_time, but it's
|
|
# OK at the time of writing.
|
|
print("Seconds: {0.seconds}".format(yesterday_sun_set_time - today_sun_set_time))
|