From f09544bbee0606a52482400d4e182b8ebf427ea1 Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Wed, 28 Aug 2024 11:24:18 +0200 Subject: [PATCH 01/17] First moon bot --- .gitignore | 2 + bot/Dockerfile | 1 + bot/moon.php | 269 +++++++++++++++++++++++++++++++++++++++++++++++ bot/testbot.py | 26 +++++ bot/testmoon.py | 44 ++++++++ bot/testmoon2.py | 99 +++++++++++++++++ 6 files changed, 441 insertions(+) create mode 100644 bot/Dockerfile create mode 100644 bot/moon.php create mode 100644 bot/testbot.py create mode 100644 bot/testmoon.py create mode 100644 bot/testmoon2.py diff --git a/.gitignore b/.gitignore index 3f35a11..53a2c0a 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,5 @@ /vendors/* .DS_Store +__pycache__ +*.secret diff --git a/bot/Dockerfile b/bot/Dockerfile new file mode 100644 index 0000000..6efd40d --- /dev/null +++ b/bot/Dockerfile @@ -0,0 +1 @@ +# pip3 install Mastodon.py \ No newline at end of file diff --git a/bot/moon.php b/bot/moon.php new file mode 100644 index 0000000..823d920 --- /dev/null +++ b/bot/moon.php @@ -0,0 +1,269 @@ += 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 = ''; + 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 = ''; + 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 = ''; + 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 = ''; + 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)); + + +?> \ No newline at end of file diff --git a/bot/testbot.py b/bot/testbot.py new file mode 100644 index 0000000..d01063a --- /dev/null +++ b/bot/testbot.py @@ -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]) \ No newline at end of file diff --git a/bot/testmoon.py b/bot/testmoon.py new file mode 100644 index 0000000..63cd1bf --- /dev/null +++ b/bot/testmoon.py @@ -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) \ No newline at end of file diff --git a/bot/testmoon2.py b/bot/testmoon2.py new file mode 100644 index 0000000..2c71229 --- /dev/null +++ b/bot/testmoon2.py @@ -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")) \ No newline at end of file -- 2.43.5 From 80dff07d94b45b19b782f2170183866678eb350f Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Wed, 28 Aug 2024 21:45:31 +0200 Subject: [PATCH 02/17] Maybe a docker build --- .woodpecker/docker.yml | 4 +++- bot/Dockerfile | 10 +++++++++- bot/requirements.txt | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 bot/requirements.txt diff --git a/.woodpecker/docker.yml b/.woodpecker/docker.yml index e8ba8d5..ec49e3c 100644 --- a/.woodpecker/docker.yml +++ b/.woodpecker/docker.yml @@ -3,7 +3,9 @@ pipeline: secrets: [docker_username, docker_password] image: woodpeckerci/plugin-docker-buildx settings: - repo: dentaku/vollmond + context: bot + # dockerfile: bot/Dockerfile + repo: dentaku/vollmond-bot tag: latest auto-tag: true platforms: [linux/amd64, linux/arm64] \ No newline at end of file diff --git a/bot/Dockerfile b/bot/Dockerfile index 6efd40d..991e9ce 100644 --- a/bot/Dockerfile +++ b/bot/Dockerfile @@ -1 +1,9 @@ -# pip3 install Mastodon.py \ No newline at end of file +FROM python:3 +WORKDIR /usr/src/app + +COPY requirements.txt ./ +RUN pip install --no-cache-dir -r requirements.txt + +COPY . . + +CMD [ "python", "./testbot.py" ] \ No newline at end of file diff --git a/bot/requirements.txt b/bot/requirements.txt new file mode 100644 index 0000000..b033626 --- /dev/null +++ b/bot/requirements.txt @@ -0,0 +1 @@ +Mastodon.py \ No newline at end of file -- 2.43.5 From a149d77461b89ffbb613e5615515f1215eaf63a0 Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Wed, 28 Aug 2024 21:51:17 +0200 Subject: [PATCH 03/17] Explicitly set Dockerfile location --- .woodpecker/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.woodpecker/docker.yml b/.woodpecker/docker.yml index ec49e3c..fa185e4 100644 --- a/.woodpecker/docker.yml +++ b/.woodpecker/docker.yml @@ -4,7 +4,7 @@ pipeline: image: woodpeckerci/plugin-docker-buildx settings: context: bot - # dockerfile: bot/Dockerfile + dockerfile: bot/Dockerfile repo: dentaku/vollmond-bot tag: latest auto-tag: true -- 2.43.5 From b1a4fedbf663514b74739f8b8a8a16abe277aac7 Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Wed, 4 Sep 2024 17:55:36 +0200 Subject: [PATCH 04/17] =?UTF-8?q?Don=E2=80=99t=20put=20the=20Dockerfile=20?= =?UTF-8?q?into=20the=20container?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot/.dockerignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 bot/.dockerignore diff --git a/bot/.dockerignore b/bot/.dockerignore new file mode 100644 index 0000000..1bc8fe2 --- /dev/null +++ b/bot/.dockerignore @@ -0,0 +1,2 @@ +*.secret +Dockerfile \ No newline at end of file -- 2.43.5 From cef8ee775e9da714a746d255050a9f5c80c832d5 Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Sat, 7 Sep 2024 17:04:50 +0200 Subject: [PATCH 05/17] Sichelond (fixes #4 ) --- bot/testmoon2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/testmoon2.py b/bot/testmoon2.py index 2c71229..77578ab 100644 --- a/bot/testmoon2.py +++ b/bot/testmoon2.py @@ -76,7 +76,7 @@ def moon_phase_as_text(mday): if (till_next_full < datetime.timedelta(days=10)): return("🌓 Zunehmender Halbmond") if (till_next_full < datetime.timedelta(days=14)): - return("🌒 Zunehmender Sichelond") + return("🌒 Zunehmender Sichelmond") if (till_next_full < datetime.timedelta(days=16)): return("🌑 Neumond") if (till_next_full < datetime.timedelta(days=20)): -- 2.43.5 From 0963e34707f6a2defd46a63fb9bd45619bce62eb Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Sat, 7 Sep 2024 17:47:01 +0200 Subject: [PATCH 06/17] Join both builds --- .woodpecker/docker.yml | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/.woodpecker/docker.yml b/.woodpecker/docker.yml index fa185e4..eea53ce 100644 --- a/.woodpecker/docker.yml +++ b/.woodpecker/docker.yml @@ -1,11 +1,36 @@ -pipeline: - docker-build: +steps: + build-bot: secrets: [docker_username, docker_password] image: woodpeckerci/plugin-docker-buildx settings: context: bot dockerfile: bot/Dockerfile repo: dentaku/vollmond-bot - tag: latest + tags: + - latest + - v0.1 auto-tag: true - platforms: [linux/amd64, linux/arm64] \ No newline at end of file + platforms: [linux/amd64, linux/arm64] + when: + - event: push + path: + include: [ 'bot/**' ] + - event: cron + - event: manual + + build-webpage: + secrets: [docker_username, docker_password] + image: woodpeckerci/plugin-docker-buildx + settings: + repo: dentaku/vollmond + tags: + - latest + - v1.0 + auto-tag: true + platforms: [linux/amd64, linux/arm64] + when: + - event: push + path: + include: [ 'wwwroot/**', 'Dockerfile' ] + - event: cron + - event: manual \ No newline at end of file -- 2.43.5 From de9c3a881c105611e890bc23d62980538f70ad30 Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Tue, 10 Sep 2024 08:33:32 +0200 Subject: [PATCH 07/17] Secrets may not be passed as environment variables anymore. --- .woodpecker/docker.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.woodpecker/docker.yml b/.woodpecker/docker.yml index eea53ce..cad3e0a 100644 --- a/.woodpecker/docker.yml +++ b/.woodpecker/docker.yml @@ -1,8 +1,11 @@ steps: build-bot: - secrets: [docker_username, docker_password] image: woodpeckerci/plugin-docker-buildx settings: + username: + from_secret: docker_username + password: + from_secret: docker_password context: bot dockerfile: bot/Dockerfile repo: dentaku/vollmond-bot @@ -19,9 +22,12 @@ steps: - event: manual build-webpage: - secrets: [docker_username, docker_password] image: woodpeckerci/plugin-docker-buildx settings: + username: + from_secret: docker_username + password: + from_secret: docker_password repo: dentaku/vollmond tags: - latest -- 2.43.5 From e84aee17d5c1312c5295e460030209bb577f3a66 Mon Sep 17 00:00:00 2001 From: dentaku Date: Wed, 30 Oct 2024 14:53:06 +0000 Subject: [PATCH 08/17] Remove Matomo (Piwik) code web analytics feel so obsolete --- wwwroot/index.php | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/wwwroot/index.php b/wwwroot/index.php index 4e25bfe..1871f1d 100644 --- a/wwwroot/index.php +++ b/wwwroot/index.php @@ -81,21 +81,6 @@ echo "\n\n"; $vollmond=(abs($datum-time())<43200); ?> Ist schon wieder Vollmond? - <?php echo($vollmond?"Ja":"Nein"); ?> - - - - -- 2.43.5 From 3a6a0f86a36a9105a4f1bf149733b36c0d52251f Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Fri, 1 Nov 2024 11:16:17 +0100 Subject: [PATCH 09/17] Bump version to 1.1 --- .woodpecker/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.woodpecker/docker.yml b/.woodpecker/docker.yml index cad3e0a..176114a 100644 --- a/.woodpecker/docker.yml +++ b/.woodpecker/docker.yml @@ -31,7 +31,7 @@ steps: repo: dentaku/vollmond tags: - latest - - v1.0 + - v1.1 auto-tag: true platforms: [linux/amd64, linux/arm64] when: -- 2.43.5 From f0cab8794caa3093360a4e8e7d0fe1d2cf20bbb6 Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Fri, 1 Nov 2024 12:00:09 +0100 Subject: [PATCH 10/17] Refactoring (renaming) --- bot/moon.php | 269 ---------------------------------- bot/{testmoon2.py => moon.py} | 0 bot/testbot.py | 6 +- bot/testmoon.py | 44 ------ 4 files changed, 3 insertions(+), 316 deletions(-) delete mode 100644 bot/moon.php rename bot/{testmoon2.py => moon.py} (100%) delete mode 100644 bot/testmoon.py diff --git a/bot/moon.php b/bot/moon.php deleted file mode 100644 index 823d920..0000000 --- a/bot/moon.php +++ /dev/null @@ -1,269 +0,0 @@ -= 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 = ''; - 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 = ''; - 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 = ''; - 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 = ''; - 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)); - - -?> \ No newline at end of file diff --git a/bot/testmoon2.py b/bot/moon.py similarity index 100% rename from bot/testmoon2.py rename to bot/moon.py diff --git a/bot/testbot.py b/bot/testbot.py index d01063a..08a4df6 100644 --- a/bot/testbot.py +++ b/bot/testbot.py @@ -1,5 +1,5 @@ import datetime -import testmoon2 +import moon from mastodon import Mastodon # Set up Mastodon @@ -12,9 +12,9 @@ mastodon = Mastodon( now = datetime.datetime.now() moon_text="Aktuelle Mondphase:\n" -moon_text+=testmoon2.moon_phase_as_text(now) +moon_text+=moon.moon_phase_as_text(now) moon_text+="\n" -moon_text+=testmoon2.till_next_full_as_text(now) +moon_text+=moon.till_next_full_as_text(now) print(moon_text) mastodon.status_post(moon_text) diff --git a/bot/testmoon.py b/bot/testmoon.py deleted file mode 100644 index 63cd1bf..0000000 --- a/bot/testmoon.py +++ /dev/null @@ -1,44 +0,0 @@ -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) \ No newline at end of file -- 2.43.5 From 5ae27d600000fd3535bef403d65b7e18c70569f0 Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Fri, 1 Nov 2024 12:01:47 +0100 Subject: [PATCH 11/17] Rafactor (rename part 2) --- bot/Dockerfile | 2 +- bot/{testbot.py => bot.py} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename bot/{testbot.py => bot.py} (100%) diff --git a/bot/Dockerfile b/bot/Dockerfile index 991e9ce..8e6e9ba 100644 --- a/bot/Dockerfile +++ b/bot/Dockerfile @@ -6,4 +6,4 @@ RUN pip install --no-cache-dir -r requirements.txt COPY . . -CMD [ "python", "./testbot.py" ] \ No newline at end of file +CMD [ "python", "./bot.py" ] \ No newline at end of file diff --git a/bot/testbot.py b/bot/bot.py similarity index 100% rename from bot/testbot.py rename to bot/bot.py -- 2.43.5 From 510a56c16b1ff46e47ced4854f65fcb34ca3778d Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Fri, 1 Nov 2024 16:26:46 +0100 Subject: [PATCH 12/17] Add (basic) editorconfig --- .editorconfig | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..c1322dc --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# top-most EditorConfig file +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = false +insert_final_newline = false \ No newline at end of file -- 2.43.5 From 8acc8a0af82e4282283ddef36956d61efcee0935 Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Fri, 1 Nov 2024 16:27:17 +0100 Subject: [PATCH 13/17] Add pytz (python timezone module) --- bot/requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bot/requirements.txt b/bot/requirements.txt index b033626..8c3eaac 100644 --- a/bot/requirements.txt +++ b/bot/requirements.txt @@ -1 +1,2 @@ -Mastodon.py \ No newline at end of file +Mastodon.py +pytz \ No newline at end of file -- 2.43.5 From c70159e31bf2f0b67e3df43e0d633dfaf7a317ab Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Fri, 1 Nov 2024 16:29:18 +0100 Subject: [PATCH 14/17] =?UTF-8?q?Fix=20timezone=20handling,=20don=E2=80=99?= =?UTF-8?q?t=20display=20timedelta=20during=20full=20moon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot/bot.py | 13 ++++------ bot/moon.py | 71 +++++++++++++++++++++++++++++++---------------------- 2 files changed, 46 insertions(+), 38 deletions(-) diff --git a/bot/bot.py b/bot/bot.py index 08a4df6..d25ae9e 100644 --- a/bot/bot.py +++ b/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]) \ No newline at end of file diff --git a/bot/moon.py b/bot/moon.py index 77578ab..d566ca6 100644 --- a/bot/moon.py +++ b/bot/moon.py @@ -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 @@ -34,10 +36,10 @@ def next_full_moon(start): z = math.floor(JDE + 0.5) f = (JDE + 0.5) - math.floor(JDE + 0.5) if (z < 2299161): - a = z + a = z else: - g = math.floor((z - 1867216.25) / 36524.25) - a = z + 1 + g - math.floor(g / 4) + 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) @@ -54,37 +56,46 @@ def next_full_moon(start): tag = math.floor(tag_temp) if (e < 14): - monat = e -1 + monat = e -1 else: - monat = e - 13 + monat = e - 13 if (monat > 2): - jahr = c - 4716 + jahr = c - 4716 else: - jahr = c - 4715 + jahr = c - 4715 + + fmutc = datetime(jahr, monat, tag, stunde, minute, sekunde, tzinfo=timezone('UTC')) - return datetime.datetime(jahr, monat, tag, stunde, minute, sekunde) + 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): -- 2.43.5 From c4c9b226ac16030b6fd83611cafef5c3dc470b80 Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Fri, 1 Nov 2024 16:35:53 +0100 Subject: [PATCH 15/17] Make MASTODON_URL configurable --- bot/bot.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bot/bot.py b/bot/bot.py index d25ae9e..f932efd 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -1,3 +1,4 @@ +import os import moon from mastodon import Mastodon from pytz import timezone @@ -5,9 +6,8 @@ from datetime import datetime # Set up Mastodon mastodon = Mastodon( - access_token = 'testtoken.secret', - # api_base_url = 'https://fnordon.de/' - api_base_url = 'https://mastodon.wazongtest.de/' + access_token = 'token.secret', + api_base_url = os.getenv('MASTODON_URL', 'https://mastodon.wazongtest.de/') ) tz = timezone('Europe/Berlin') -- 2.43.5 From 34c5188bd1203b784a556e87247d7b7a1ed8f50b Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Fri, 1 Nov 2024 16:36:13 +0100 Subject: [PATCH 16/17] Bump bot version to 0.2 --- .woodpecker/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.woodpecker/docker.yml b/.woodpecker/docker.yml index 176114a..baf9dfd 100644 --- a/.woodpecker/docker.yml +++ b/.woodpecker/docker.yml @@ -11,7 +11,7 @@ steps: repo: dentaku/vollmond-bot tags: - latest - - v0.1 + - v0.2 auto-tag: true platforms: [linux/amd64, linux/arm64] when: -- 2.43.5 From 98e7118203e04a145717e7d69f9a980b42dad9aa Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Sun, 17 Nov 2024 15:38:23 +0100 Subject: [PATCH 17/17] Python formatter --- bot/moon.py | 49 +++++++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/bot/moon.py b/bot/moon.py index d566ca6..874dc02 100644 --- a/bot/moon.py +++ b/bot/moon.py @@ -3,14 +3,16 @@ from pytz import timezone from datetime import datetime from datetime import timedelta + def next_full_moon(start): # 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) 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 @@ -20,7 +22,7 @@ def next_full_moon(start): 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) @@ -45,7 +47,8 @@ def next_full_moon(start): 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 + # //Tag incl. Tagesbruchteilen + tag_temp = b - d - math.floor(30.6001 * e) + f stunde_temp = (tag_temp - math.floor(tag_temp)) * 24 minute_temp = (stunde_temp - math.floor(stunde_temp)) * 60 @@ -56,7 +59,7 @@ def next_full_moon(start): tag = math.floor(tag_temp) if (e < 14): - monat = e -1 + monat = e - 1 else: monat = e - 13 @@ -64,39 +67,44 @@ def next_full_moon(start): jahr = c - 4716 else: 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) + def is_full_moon(mday: datetime): 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)): 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") + till_next_full_text = strfdelta( + till_next_full, "{days} Tage {hours} Stunden bis Vollmond") if (till_next_full < timedelta(days=1)): - return("🌕 Vollmond") + return ("🌕 Vollmond") 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)): - return("🌓 Zunehmender Halbmond\n" + till_next_full_text) + return ("🌓 Zunehmender Halbmond\n" + till_next_full_text) 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)): - return("🌑 Neumond\n" + till_next_full_text) + return ("🌑 Neumond\n" + till_next_full_text) 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)): - return("🌗 Abnehmender Halbmond\n" + till_next_full_text) + 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") + return ("🌖 Abnehmender Dreiviertelmond\n" + till_next_full_text) + return ("🌕 Vollmond") + def strfdelta(tdelta, fmt): d = {"days": tdelta.days} @@ -104,7 +112,8 @@ def strfdelta(tdelta, fmt): 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")) \ No newline at end of file + till_next_full = nmoon-mday + return (strfdelta(till_next_full, "{days} Tage {hours} Stunden bis Vollmond")) -- 2.43.5