Python formatter
All checks were successful
ci/woodpecker/push/docker Pipeline was successful
ci/woodpecker/pr/docker Pipeline was successful
ci/woodpecker/pull_request_closed/docker Pipeline was successful

This commit is contained in:
Thomas Renger 2024-11-17 15:38:23 +01:00
parent 34c5188bd1
commit 98e7118203

View file

@ -3,10 +3,12 @@ from pytz import timezone
from datetime import datetime from datetime import datetime
from datetime import timedelta from datetime import timedelta
def next_full_moon(start): def next_full_moon(start):
# date of the known full moon # date of the known full moon
y2k = datetime(1999, 12, 22, 18, 31, 18).astimezone(timezone('Europe/Berlin')) y2k = datetime(1999, 12, 22, 18, 31, 18).astimezone(
timezone('Europe/Berlin'))
since2000 = (start - y2k) / timedelta(days=365.25) since2000 = (start - y2k) / timedelta(days=365.25)
rads = 3.14159265359/180 rads = 3.14159265359/180
@ -45,7 +47,8 @@ def next_full_moon(start):
d = math.floor(365.25 * c) d = math.floor(365.25 * c)
e = math.floor((b - d) / 30.6001) e = math.floor((b - d) / 30.6001)
tag_temp = b - d - math.floor(30.6001 * e) + f # //Tag incl. Tagesbruchteilen # //Tag incl. Tagesbruchteilen
tag_temp = b - d - math.floor(30.6001 * e) + f
stunde_temp = (tag_temp - math.floor(tag_temp)) * 24 stunde_temp = (tag_temp - math.floor(tag_temp)) * 24
minute_temp = (stunde_temp - math.floor(stunde_temp)) * 60 minute_temp = (stunde_temp - math.floor(stunde_temp)) * 60
@ -65,10 +68,12 @@ def next_full_moon(start):
else: else:
jahr = c - 4715 jahr = c - 4715
fmutc = datetime(jahr, monat, tag, stunde, minute, sekunde, tzinfo=timezone('UTC')) fmutc = datetime(jahr, monat, tag, stunde, minute,
sekunde, tzinfo=timezone('UTC'))
return fmutc.astimezone(start.tzinfo) return fmutc.astimezone(start.tzinfo)
def is_full_moon(mday: datetime): def is_full_moon(mday: datetime):
nmoon = next_full_moon(mday) nmoon = next_full_moon(mday)
till_next_full = nmoon-mday till_next_full = nmoon-mday
@ -76,10 +81,12 @@ def is_full_moon(mday: datetime):
return True return True
return False return False
def moon_phase_as_text(mday: datetime): def moon_phase_as_text(mday: datetime):
nmoon = next_full_moon(mday) nmoon = next_full_moon(mday)
till_next_full = nmoon - mday till_next_full = nmoon - mday
till_next_full_text = strfdelta(till_next_full, "{days} Tage {hours} Stunden bis Vollmond") till_next_full_text = strfdelta(
till_next_full, "{days} Tage {hours} Stunden bis Vollmond")
if (till_next_full < timedelta(days=1)): if (till_next_full < timedelta(days=1)):
return ("🌕 Vollmond") return ("🌕 Vollmond")
if (till_next_full < timedelta(days=6)): if (till_next_full < timedelta(days=6)):
@ -98,12 +105,14 @@ def moon_phase_as_text(mday: datetime):
return ("🌖 Abnehmender Dreiviertelmond\n" + till_next_full_text) return ("🌖 Abnehmender Dreiviertelmond\n" + till_next_full_text)
return ("🌕 Vollmond") return ("🌕 Vollmond")
def strfdelta(tdelta, fmt): def strfdelta(tdelta, fmt):
d = {"days": tdelta.days} d = {"days": tdelta.days}
d["hours"], rem = divmod(tdelta.seconds, 3600) d["hours"], rem = divmod(tdelta.seconds, 3600)
d["minutes"], d["seconds"] = divmod(rem, 60) d["minutes"], d["seconds"] = divmod(rem, 60)
return fmt.format(**d) return fmt.format(**d)
def till_next_full_as_text(mday): def till_next_full_as_text(mday):
nmoon = next_full_moon(mday) nmoon = next_full_moon(mday)
till_next_full = nmoon-mday till_next_full = nmoon-mday