The Bot for @vollmond@fnordon.de #5
49
bot/moon.py
49
bot/moon.py
|
@ -3,14 +3,16 @@ 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
|
||||||
phase = 0.5 # 0.5 equals full moon
|
phase = 0.5 # 0.5 equals full moon
|
||||||
# Anzahl der Mondphasen seit 2000
|
# Anzahl der Mondphasen seit 2000
|
||||||
k = math.floor((since2000)*12.36853087)+phase
|
k = math.floor((since2000)*12.36853087)+phase
|
||||||
|
|
||||||
|
@ -20,7 +22,7 @@ def next_full_moon(start):
|
||||||
M = (2.5534+29.10535670*k)*rads
|
M = (2.5534+29.10535670*k)*rads
|
||||||
Ms = (201.5643+385.81693528*k)*rads
|
Ms = (201.5643+385.81693528*k)*rads
|
||||||
F = (160.7108+390.67050284*k)*rads
|
F = (160.7108+390.67050284*k)*rads
|
||||||
|
|
||||||
# Korrekturterme JDE fuer Vollmond
|
# Korrekturterme JDE fuer Vollmond
|
||||||
JDE += -0.40614*math.sin(Ms)
|
JDE += -0.40614*math.sin(Ms)
|
||||||
JDE += 0.17302*math.sin(M)
|
JDE += 0.17302*math.sin(M)
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -56,7 +59,7 @@ def next_full_moon(start):
|
||||||
tag = math.floor(tag_temp)
|
tag = math.floor(tag_temp)
|
||||||
|
|
||||||
if (e < 14):
|
if (e < 14):
|
||||||
monat = e -1
|
monat = e - 1
|
||||||
else:
|
else:
|
||||||
monat = e - 13
|
monat = e - 13
|
||||||
|
|
||||||
|
@ -64,39 +67,44 @@ def next_full_moon(start):
|
||||||
jahr = c - 4716
|
jahr = c - 4716
|
||||||
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
|
||||||
if (till_next_full < timedelta(days=1) or till_next_full < timedelta(days=28)):
|
if (till_next_full < timedelta(days=1) or till_next_full < timedelta(days=28)):
|
||||||
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)):
|
||||||
return("🌔 Zunehmender Dreiviertelmond\n" + till_next_full_text)
|
return ("🌔 Zunehmender Dreiviertelmond\n" + till_next_full_text)
|
||||||
if (till_next_full < timedelta(days=10)):
|
if (till_next_full < timedelta(days=10)):
|
||||||
return("🌓 Zunehmender Halbmond\n" + till_next_full_text)
|
return ("🌓 Zunehmender Halbmond\n" + till_next_full_text)
|
||||||
if (till_next_full < timedelta(days=14)):
|
if (till_next_full < timedelta(days=14)):
|
||||||
return("🌒 Zunehmender Sichelmond\n" + till_next_full_text)
|
return ("🌒 Zunehmender Sichelmond\n" + till_next_full_text)
|
||||||
if (till_next_full < timedelta(days=16)):
|
if (till_next_full < timedelta(days=16)):
|
||||||
return("🌑 Neumond\n" + till_next_full_text)
|
return ("🌑 Neumond\n" + till_next_full_text)
|
||||||
if (till_next_full < timedelta(days=20)):
|
if (till_next_full < timedelta(days=20)):
|
||||||
return("🌘 Abnehmender Sichelmond\n" + till_next_full_text)
|
return ("🌘 Abnehmender Sichelmond\n" + till_next_full_text)
|
||||||
if (till_next_full < timedelta(days=24)):
|
if (till_next_full < timedelta(days=24)):
|
||||||
return("🌗 Abnehmender Halbmond\n" + till_next_full_text)
|
return ("🌗 Abnehmender Halbmond\n" + till_next_full_text)
|
||||||
if (till_next_full < timedelta(days=28.5)):
|
if (till_next_full < timedelta(days=28.5)):
|
||||||
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}
|
||||||
|
@ -104,7 +112,8 @@ def strfdelta(tdelta, fmt):
|
||||||
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
|
||||||
return(strfdelta(till_next_full, "{days} Tage {hours} Stunden bis Vollmond"))
|
return (strfdelta(till_next_full, "{days} Tage {hours} Stunden bis Vollmond"))
|
||||||
|
|
Loading…
Reference in a new issue