The Bot for @vollmond@fnordon.de #5

Merged
dentaku merged 17 commits from beta-bot into main 2024-11-17 15:26:19 +00:00
2 changed files with 46 additions and 38 deletions
Showing only changes of commit c70159e31b - Show all commits

View file

@ -1,6 +1,7 @@
import datetime
import moon
from mastodon import Mastodon
from pytz import timezone
from datetime import datetime
# Set up Mastodon
mastodon = Mastodon(
@ -9,18 +10,14 @@ mastodon = Mastodon(
api_base_url = 'https://mastodon.wazongtest.de/'
)
now = datetime.datetime.now()
tz = timezone('Europe/Berlin')
now = datetime.now().astimezone(tz)
moon_text="Aktuelle Mondphase:\n"
moon_text+=moon.moon_phase_as_text(now)
moon_text+="\n"
moon_text+=moon.till_next_full_as_text(now)
print(moon_text)
mastodon.status_post(moon_text)
mastodon.status_post(moon_text, visibility='unlisted')
me = mastodon.me()
print(me['id'])
print(mastodon.account_statuses(me['id'])[0])

View file

@ -1,14 +1,16 @@
import datetime
import math
from pytz import timezone
from datetime import datetime
from datetime import timedelta
def next_full_moon(start):
# y2k = datetime.datetime(2000, 1, 1)
y2k = datetime.datetime(1999, 12, 22, 18, 31, 18)
since2000 = (start - y2k) / datetime.timedelta(days=365.25)
# date of the known full moon
y2k = datetime(1999, 12, 22, 18, 31, 18).astimezone(timezone('Europe/Berlin'))
since2000 = (start - y2k) / timedelta(days=365.25)
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
k = math.floor((since2000)*12.36853087)+phase
@ -63,28 +65,37 @@ def next_full_moon(start):
else:
jahr = c - 4715
return datetime.datetime(jahr, monat, tag, stunde, minute, sekunde)
fmutc = datetime(jahr, monat, tag, stunde, minute, sekunde, tzinfo=timezone('UTC'))
return fmutc.astimezone(start.tzinfo)
def moon_phase_as_text(mday):
def is_full_moon(mday: datetime):
nmoon = next_full_moon(mday)
till_next_full=nmoon-mday
if (till_next_full < datetime.timedelta(days=1)):
if (till_next_full < timedelta(days=1) or till_next_full < timedelta(days=28)):
return True
return False
def moon_phase_as_text(mday: datetime):
nmoon = next_full_moon(mday)
till_next_full = nmoon - mday
till_next_full_text = strfdelta(till_next_full, "{days} Tage {hours} Stunden bis Vollmond")
if (till_next_full < timedelta(days=1)):
return("🌕 Vollmond")
if (till_next_full < datetime.timedelta(days=6)):
return("🌔 Zunehmender Dreiviertelmond")
if (till_next_full < datetime.timedelta(days=10)):
return("🌓 Zunehmender Halbmond")
if (till_next_full < datetime.timedelta(days=14)):
return("🌒 Zunehmender Sichelmond")
if (till_next_full < datetime.timedelta(days=16)):
return("🌑 Neumond")
if (till_next_full < datetime.timedelta(days=20)):
return("🌘 Abnehmender Sichelmond")
if (till_next_full < datetime.timedelta(days=24)):
return("🌗 Abnehmender Halbmond")
if (till_next_full < datetime.timedelta(days=28)):
return("🌖 Abnehmender Dreiviertelmond")
if (till_next_full < timedelta(days=6)):
return("🌔 Zunehmender Dreiviertelmond\n" + till_next_full_text)
if (till_next_full < timedelta(days=10)):
return("🌓 Zunehmender Halbmond\n" + till_next_full_text)
if (till_next_full < timedelta(days=14)):
return("🌒 Zunehmender Sichelmond\n" + till_next_full_text)
if (till_next_full < timedelta(days=16)):
return("🌑 Neumond\n" + till_next_full_text)
if (till_next_full < timedelta(days=20)):
return("🌘 Abnehmender Sichelmond\n" + till_next_full_text)
if (till_next_full < timedelta(days=24)):
return("🌗 Abnehmender Halbmond\n" + till_next_full_text)
if (till_next_full < timedelta(days=28.5)):
return("🌖 Abnehmender Dreiviertelmond\n" + till_next_full_text)
return("🌕 Vollmond")
def strfdelta(tdelta, fmt):