First moon bot
This commit is contained in:
parent
fe54c064f1
commit
f09544bbee
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -26,3 +26,5 @@
|
|||
/vendors/*
|
||||
|
||||
.DS_Store
|
||||
__pycache__
|
||||
*.secret
|
||||
|
|
1
bot/Dockerfile
Normal file
1
bot/Dockerfile
Normal file
|
@ -0,0 +1 @@
|
|||
# pip3 install Mastodon.py
|
269
bot/moon.php
Normal file
269
bot/moon.php
Normal file
|
@ -0,0 +1,269 @@
|
|||
<?
|
||||
|
||||
// Formel nach http://www.die-seite.eu/wm-mondphasen.php
|
||||
|
||||
$ursprung = mktime(19,19,54,02,22,2016);
|
||||
$akt_date = time(); //mktime(18,19,54,04,24,2016);//
|
||||
define('ZYCLUS', floor(29.530588861 * 86400));
|
||||
$mondphase = round(((($akt_date - $ursprung) / ZYCLUS) - floor(($akt_date - $ursprung) / ZYCLUS)) * 100, 0);
|
||||
|
||||
|
||||
function rescale($ab, $cd) //--Funktion zum anpassen der Mondphase 0-100 an Bildnummer 001-362 (Bilder der Seite http://www.avgoe.de)
|
||||
{
|
||||
list($a1,$b1) = $ab;
|
||||
list($c1,$d1) = $cd;
|
||||
if($a1 == $b1)
|
||||
{
|
||||
trigger_error("Invalid scale",E_USER_WARNING);
|
||||
return false;
|
||||
}
|
||||
$o = ($b1*$c1-$a1*$d1)/($b1-$a1);
|
||||
$s = ($d1-$c1)/($b1-$a1);
|
||||
return function($x)use($o,$s)
|
||||
{
|
||||
return $s*$x+$o;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
if ($mondphase <= 1 || $mondphase >= 99 ){ //--Vollmond
|
||||
$phase_text = 'Vollmond';
|
||||
if($mondphase>=99){
|
||||
$pic = rescale([99,100],[172,177]);} // ([Mondphasen von,bis],[Bildnummern von,bis])
|
||||
else{
|
||||
$pic = rescale([0,1],[178,182]);}
|
||||
$pic_n = floor($pic($mondphase));
|
||||
if($pic_n<10){
|
||||
$pic_n = "00".$pic_n;}
|
||||
elseif($pic_n<100){
|
||||
$pic_n = "0".$pic_n;}
|
||||
else{$pic_n = $pic_n;}
|
||||
$path = '<IMG src="/user/mond/mond_'.$pic_n.'.gif">';
|
||||
setvalue(32646 /*[Wetterdaten\Astronomische Daten\Mondansicht]*/, $path);
|
||||
}
|
||||
elseif ($mondphase > 1 && $mondphase < 49){ //--abnehmender Mond
|
||||
$phase_text = 'abnehmender Mond';
|
||||
$pic = rescale([2,48],[183,352]);
|
||||
$pic_n = floor($pic($mondphase));
|
||||
if($pic_n<10){
|
||||
$pic_n = "00".$pic_n;}
|
||||
elseif($pic_n<100){
|
||||
$pic_n = "0".$pic_n;}
|
||||
else{$pic_n = $pic_n;}
|
||||
$path = '<IMG src="/user/mond/mond_'.$pic_n.'.gif">';
|
||||
setvalue(32646 /*[Wetterdaten\Astronomische Daten\Mondansicht]*/, $path);
|
||||
}
|
||||
elseif ($mondphase >= 49 && $mondphase <= 51){ //--Neumond
|
||||
$phase_text = 'Neumond';
|
||||
$pic = rescale([49,51],[353,362]);
|
||||
$pic_n = floor($pic($mondphase));
|
||||
if($pic_n<10){
|
||||
$pic_n = "00".$pic_n;}
|
||||
elseif($pic_n<100){
|
||||
$pic_n = "0".$pic_n;}
|
||||
else{$pic_n = $pic_n;}
|
||||
$path = '<IMG src="/user/mond/mond_'.$pic_n.'.gif">';
|
||||
setvalue(32646 /*[Wetterdaten\Astronomische Daten\Mondansicht]*/, $path);
|
||||
}
|
||||
else{ //--zunehmender Mond
|
||||
$phase_text = 'zunehmender Mond';
|
||||
$pic = rescale([52,98],[008,171]);
|
||||
$pic_n = floor($pic($mondphase));
|
||||
if($pic_n<10){
|
||||
$pic_n = "00".$pic_n;}
|
||||
elseif($pic_n<100){
|
||||
$pic_n = "0".$pic_n;}
|
||||
else{$pic_n = $pic_n;}
|
||||
$path = '<IMG src="/user/mond/mond_'.$pic_n.'.gif">';
|
||||
setvalue(32646 /*[Wetterdaten\Astronomische Daten\Mondansicht]*/, $path);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// ============================================================
|
||||
//
|
||||
// Phasen: phase = 0 für Neumond
|
||||
// phase = 0.25 für erstes Viertel
|
||||
// phase = 0.5 für Vollmond
|
||||
// phase = 0.75 für letztes Viertel
|
||||
// Für Werte anders als 0, 0.25, 0.5 oder 0.75 ist nachstehendes Script ungültig.
|
||||
// Angabe des Zeitpunktes als Fließkomma-Jahreszahl
|
||||
// Bsp.: 1.8.2006 = ca. 2006.581
|
||||
//
|
||||
// Ergebnis: $JDE
|
||||
// ============================================================
|
||||
|
||||
// aktuelles Datum in Jahre umrechnen
|
||||
$year = ((((((date("s") / 60)+ date("i")) / 60)+date("G")) / 24) + date("z") - 1) / (365 + (date("L"))) + date("Y");
|
||||
//print_r(date("z"));
|
||||
$rads = 3.14159265359/180;
|
||||
|
||||
$table = "";
|
||||
$name = "";
|
||||
|
||||
for ($phase = 0; $phase < 1; $phase += 0.25){
|
||||
// Anzahl der Mondphasen seit 2000
|
||||
$k = floor(($year-2000)*12.36853087)+$phase;
|
||||
// Mittlerer JDE Wert des Ereignisses
|
||||
$JDE = 2451550.09766+29.530588861*$k;
|
||||
// Relevante Winkelwerte in [Radiant]
|
||||
$M = (2.5534+29.10535670*$k)*$rads;
|
||||
$Ms = (201.5643+385.81693528*$k)*$rads;
|
||||
$F = (160.7108+390.67050284*$k)*$rads;
|
||||
|
||||
if ($phase == 0){
|
||||
// Korrekturterme JDE für Neumond
|
||||
$JDE += -0.40720*Sin($Ms);
|
||||
$JDE += 0.17241*Sin($M);
|
||||
$JDE += 0.01608*Sin(2*$Ms);
|
||||
$JDE += 0.01039*Sin(2*$F);
|
||||
$JDE += 0.00739*Sin($Ms-$M);
|
||||
$JDE += -0.00514*Sin($Ms+$M);
|
||||
$JDE += 0.00208*Sin(2*$M);
|
||||
$JDE += -0.00111*Sin($Ms-2*$F);
|
||||
}
|
||||
elseif ($phase == 0.5) {
|
||||
// Korrekturterme JDE für Vollmond
|
||||
$JDE += -0.40614*Sin($Ms);
|
||||
$JDE += 0.17302*Sin($M);
|
||||
$JDE += 0.01614*Sin(2*$Ms);
|
||||
$JDE += 0.01043*Sin(2*$F);
|
||||
$JDE += 0.00734*Sin($Ms-$M);
|
||||
$JDE += -0.00515*Sin($Ms+$M);
|
||||
$JDE += 0.00209*Sin(2*$M);
|
||||
$JDE += -0.00111*Sin($Ms-2*$F);
|
||||
}
|
||||
|
||||
if ($phase == 0.25 || $phase == 0.75){
|
||||
// Korrekturterme für JDE für das 1. bzw. letzte Viertel
|
||||
$JDE += -0.62801*Sin($Ms);
|
||||
$JDE += 0.17172*Sin($M);
|
||||
$JDE += -0.01183*Sin($Ms+$M);
|
||||
$JDE += 0.00862*Sin(2*$Ms);
|
||||
$JDE += 0.00804*Sin(2*$F);
|
||||
$JDE += 0.00454*Sin($Ms-$M);
|
||||
$JDE += 0.00204*Sin(2*$M);
|
||||
$JDE += -0.00180*Sin($Ms-2*$F);
|
||||
|
||||
// Weiterer Korrekturterm für Viertelphasen
|
||||
if ($phase == 0.25){
|
||||
$JDE += 0.00306;
|
||||
} else {
|
||||
$JDE += -0.00306;
|
||||
}
|
||||
}
|
||||
|
||||
// Konvertierung von Julianischem Datum auf Gregorianisches Datum
|
||||
$z = floor($JDE + 0.5);
|
||||
$f = ($JDE + 0.5) - floor($JDE + 0.5);
|
||||
if ($z < 2299161){
|
||||
$a = $z;
|
||||
}
|
||||
else {
|
||||
$g = floor(($z - 1867216.25) / 36524.25);
|
||||
$a = $z + 1 + $g - floor($g / 4);
|
||||
}
|
||||
$b = $a + 1524;
|
||||
$c = floor(($b - 122.1) / 365.25);
|
||||
$d = floor(365.25 * $c);
|
||||
$e = floor(($b - $d) / 30.6001);
|
||||
|
||||
$tag_temp = $b - $d - floor(30.6001 * $e) + $f; //Tag incl. Tagesbruchteilen
|
||||
$stunde_temp = ($tag_temp - floor($tag_temp)) * 24;
|
||||
$minute_temp = ($stunde_temp - floor($stunde_temp)) * 60;
|
||||
|
||||
$stunde = floor($stunde_temp);
|
||||
$minute = floor($minute_temp);
|
||||
$sekunde = round(($minute_temp - floor($minute_temp)) * 60);
|
||||
|
||||
$tag = floor($tag_temp);
|
||||
|
||||
if ($e < 14) {
|
||||
$monat = $e -1;
|
||||
}
|
||||
else {
|
||||
$monat = $e - 13;
|
||||
}
|
||||
if ($monat > 2) {
|
||||
$jahr = $c - 4716;
|
||||
}
|
||||
else {
|
||||
$jahr = $c - 4715;
|
||||
}
|
||||
|
||||
$sommerzeit = date("I");
|
||||
if($sommerzeit == 0){
|
||||
$datum = mktime($stunde,$minute,$sekunde+3600,$monat,$tag,$jahr);
|
||||
}
|
||||
else{
|
||||
$datum = mktime($stunde,$minute,$sekunde+7200,$monat,$tag,$jahr);
|
||||
}
|
||||
|
||||
switch ($phase){
|
||||
case 0:
|
||||
$ausgabe = 'Neumond';
|
||||
break;
|
||||
case 0.25:
|
||||
$ausgabe = 'erstes Viertel';
|
||||
break;
|
||||
case 0.5:
|
||||
$ausgabe = 'Vollmond';
|
||||
break;
|
||||
case 0.75:
|
||||
$ausgabe = 'letztes Viertel';
|
||||
break;
|
||||
}
|
||||
|
||||
$date = date("D",($datum));
|
||||
if($date == "Mon"){
|
||||
$wt = "Mo";}
|
||||
elseif ($date == "Tue"){
|
||||
$wt = "Di";}
|
||||
elseif ($date == "Wed"){
|
||||
$wt = "Mi";}
|
||||
elseif ($date == "Thu"){
|
||||
$wt = "Do";}
|
||||
elseif ($date == "Fri"){
|
||||
$wt = "Fr";}
|
||||
elseif ($date == "Sat"){
|
||||
$wt = "Sa";}
|
||||
elseif ($date == "Sun"){
|
||||
$wt = "So";}
|
||||
|
||||
$table .= ($wt.", ".date("d.m.Y H:i",($datum)).";");
|
||||
$name .= ($ausgabe.";");
|
||||
}
|
||||
|
||||
|
||||
setvalue(18785 /*[Wetterdaten\Astronomische Daten\Mondphase]*/,$phase_text." - ".$mondphase."%");
|
||||
$var = explode(";",$table);
|
||||
$var_name = explode(";",$name);
|
||||
IPS_SetName(11478 /*[Wetterdaten\Astronomische Daten\Neumond]*/, $var_name[0]);
|
||||
IPS_SetName(52027 /*[Wetterdaten\Astronomische Daten\erstes Viertel]*/, $var_name[1]);
|
||||
IPS_SetName(53514 /*[Wetterdaten\Astronomische Daten\Vollmond]*/, $var_name[2]);
|
||||
IPS_SetName(41504 /*[Wetterdaten\Astronomische Daten\letztes Viertel]*/, $var_name[3]);
|
||||
setvalue(11478 /*[Wetterdaten\Astronomische Daten\Neumond]*/, $var[0]);
|
||||
setvalue(52027 /*[Wetterdaten\Astronomische Daten\erstes Viertel]*/, $var[1]);
|
||||
setvalue(53514 /*[Wetterdaten\Astronomische Daten\Vollmond]*/, $var[2]);
|
||||
setvalue(41504 /*[Wetterdaten\Astronomische Daten\letztes Viertel]*/, $var[3]);
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Berechnung der Mondauf/untergangs Zeiten
|
||||
|
||||
$month = date("m");
|
||||
$day = date("d");
|
||||
$year = date("Y");
|
||||
|
||||
include "55184.ips.php"; // Aufruf Moon Rise/Set Script
|
||||
|
||||
$data = (Moon::calculateMoonTimes($month, $day, $year, (getvalue(29795 /*[Scripte\Sonnenauf/untergang\Breitengrad (x1000000)]*/)/1000000), (getvalue(31634 /*[Scripte\Sonnenauf/untergang\Längengrad (x1000000)]*/)/1000000)));
|
||||
|
||||
$rise = $data->{'moonrise'}; //Aufgang
|
||||
$set = $data->{'moonset'}; //Untergang
|
||||
|
||||
setvalue(55563 /*[Wetterdaten\Astronomische Daten\Mondaufgang]*/,date("H:i",$rise));
|
||||
setvalue(31319 /*[Wetterdaten\Astronomische Daten\Monduntergang]*/,date("H:i",$set));
|
||||
|
||||
|
||||
?>
|
26
bot/testbot.py
Normal file
26
bot/testbot.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
import datetime
|
||||
import testmoon2
|
||||
from mastodon import Mastodon
|
||||
|
||||
# Set up Mastodon
|
||||
mastodon = Mastodon(
|
||||
access_token = 'testtoken.secret',
|
||||
# api_base_url = 'https://fnordon.de/'
|
||||
api_base_url = 'https://mastodon.wazongtest.de/'
|
||||
)
|
||||
|
||||
|
||||
now = datetime.datetime.now()
|
||||
moon_text="Aktuelle Mondphase:\n"
|
||||
moon_text+=testmoon2.moon_phase_as_text(now)
|
||||
moon_text+="\n"
|
||||
moon_text+=testmoon2.till_next_full_as_text(now)
|
||||
print(moon_text)
|
||||
|
||||
mastodon.status_post(moon_text)
|
||||
|
||||
me = mastodon.me()
|
||||
|
||||
print(me['id'])
|
||||
|
||||
print(mastodon.account_statuses(me['id'])[0])
|
44
bot/testmoon.py
Normal file
44
bot/testmoon.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
from astral.moon import phase
|
||||
from mastodon import Mastodon
|
||||
import datetime
|
||||
|
||||
# Set up Mastodon
|
||||
mastodon = Mastodon(
|
||||
access_token = 'testtoken.secret',
|
||||
# api_base_url = 'https://fnordon.de/'
|
||||
api_base_url = 'https://mastodon.wazongtest.de/'
|
||||
)
|
||||
|
||||
now = datetime.datetime.now()
|
||||
moon_today = phase(now)
|
||||
|
||||
until_full = 14.00 - moon_today
|
||||
print("until_full", end=": ")
|
||||
print(until_full)
|
||||
if (until_full<0):
|
||||
until_full+=29.53
|
||||
print("corrected", end=": ")
|
||||
print(until_full)
|
||||
|
||||
moon_yesterday = phase(now - datetime.timedelta(days=1))
|
||||
moon_tomorrow = phase(now + datetime.timedelta(days=1))
|
||||
|
||||
next_full = now + datetime.timedelta(days=(until_full*1.055))
|
||||
|
||||
moon_text = "Next full moon " + format(next_full.isoformat())
|
||||
|
||||
# mastodon.status_post(moon_text)
|
||||
|
||||
print("Heute", end=": ")
|
||||
print(now)
|
||||
print("Mext full", end=": ")
|
||||
print(next_full)
|
||||
|
||||
print("Mond gestern", end=": ")
|
||||
print(moon_yesterday)
|
||||
print("Mond heute", end=": ")
|
||||
print(moon_today)
|
||||
print("bis Vollmond", end=": ")
|
||||
print(until_full)
|
||||
print("Mond morgen", end=": ")
|
||||
print(moon_tomorrow)
|
99
bot/testmoon2.py
Normal file
99
bot/testmoon2.py
Normal file
|
@ -0,0 +1,99 @@
|
|||
import datetime
|
||||
import math
|
||||
|
||||
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)
|
||||
|
||||
rads = 3.14159265359/180
|
||||
phase=0.5 # 0.5 equals full moon
|
||||
# Anzahl der Mondphasen seit 2000
|
||||
k = math.floor((since2000)*12.36853087)+phase
|
||||
|
||||
# Mittlerer JDE Wert des Ereignisses
|
||||
JDE = 2451550.09766+29.530588861*k
|
||||
# Relevante Winkelwerte in [Radiant]
|
||||
M = (2.5534+29.10535670*k)*rads
|
||||
Ms = (201.5643+385.81693528*k)*rads
|
||||
F = (160.7108+390.67050284*k)*rads
|
||||
|
||||
# Korrekturterme JDE fuer Vollmond
|
||||
JDE += -0.40614*math.sin(Ms)
|
||||
JDE += 0.17302*math.sin(M)
|
||||
JDE += 0.01614*math.sin(2*Ms)
|
||||
JDE += 0.01043*math.sin(2*F)
|
||||
JDE += 0.00734*math.sin(Ms-M)
|
||||
JDE += -0.00515*math.sin(Ms+M)
|
||||
JDE += 0.00209*math.sin(2*M)
|
||||
JDE += -0.00111*math.sin(Ms-2*F)
|
||||
|
||||
# Konvertierung von Julianischem Datum auf Gregorianisches Datum
|
||||
|
||||
z = math.floor(JDE + 0.5)
|
||||
f = (JDE + 0.5) - math.floor(JDE + 0.5)
|
||||
if (z < 2299161):
|
||||
a = z
|
||||
else:
|
||||
g = math.floor((z - 1867216.25) / 36524.25)
|
||||
a = z + 1 + g - math.floor(g / 4)
|
||||
b = a + 1524
|
||||
c = math.floor((b - 122.1) / 365.25)
|
||||
d = math.floor(365.25 * c)
|
||||
e = math.floor((b - d) / 30.6001)
|
||||
|
||||
tag_temp = b - d - math.floor(30.6001 * e) + f # //Tag incl. Tagesbruchteilen
|
||||
stunde_temp = (tag_temp - math.floor(tag_temp)) * 24
|
||||
minute_temp = (stunde_temp - math.floor(stunde_temp)) * 60
|
||||
|
||||
stunde = math.floor(stunde_temp)
|
||||
minute = math.floor(minute_temp)
|
||||
sekunde = round((minute_temp - math.floor(minute_temp)) * 60)
|
||||
|
||||
tag = math.floor(tag_temp)
|
||||
|
||||
if (e < 14):
|
||||
monat = e -1
|
||||
else:
|
||||
monat = e - 13
|
||||
|
||||
if (monat > 2):
|
||||
jahr = c - 4716
|
||||
else:
|
||||
jahr = c - 4715
|
||||
|
||||
return datetime.datetime(jahr, monat, tag, stunde, minute, sekunde)
|
||||
|
||||
|
||||
def moon_phase_as_text(mday):
|
||||
nmoon = next_full_moon(mday)
|
||||
till_next_full=nmoon-mday
|
||||
if (till_next_full < datetime.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 Sichelond")
|
||||
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")
|
||||
return("🌕 Vollmond")
|
||||
|
||||
def strfdelta(tdelta, fmt):
|
||||
d = {"days": tdelta.days}
|
||||
d["hours"], rem = divmod(tdelta.seconds, 3600)
|
||||
d["minutes"], d["seconds"] = divmod(rem, 60)
|
||||
return fmt.format(**d)
|
||||
|
||||
def till_next_full_as_text(mday):
|
||||
nmoon = next_full_moon(mday)
|
||||
till_next_full=nmoon-mday
|
||||
return(strfdelta(till_next_full, "{days} Tage {hours} Stunden bis Vollmond"))
|
Loading…
Reference in a new issue