The Bot for @vollmond@fnordon.de #5
13
bot/bot.py
13
bot/bot.py
|
@ -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])
|
53
bot/moon.py
53
bot/moon.py
|
@ -1,11 +1,13 @@
|
|||
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
|
||||
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue