Compare commits

..

18 commits

Author SHA1 Message Date
Thomas Renger 03e3ec912a Merge pull request 'The Bot for @vollmond@fnordon.de' (#5) from beta-bot into main
All checks were successful
ci/woodpecker/push/docker Pipeline was successful
Reviewed-on: #5
2024-11-17 15:26:19 +00:00
Thomas Renger 98e7118203 Python formatter
All checks were successful
ci/woodpecker/push/docker Pipeline was successful
ci/woodpecker/pr/docker Pipeline was successful
ci/woodpecker/pull_request_closed/docker Pipeline was successful
2024-11-17 15:38:23 +01:00
Thomas Renger 34c5188bd1 Bump bot version to 0.2
All checks were successful
ci/woodpecker/push/docker Pipeline was successful
2024-11-01 16:36:13 +01:00
Thomas Renger c4c9b226ac Make MASTODON_URL configurable 2024-11-01 16:35:53 +01:00
Thomas Renger c70159e31b Fix timezone handling, don’t display timedelta during full moon 2024-11-01 16:29:18 +01:00
Thomas Renger 8acc8a0af8 Add pytz (python timezone module) 2024-11-01 16:27:17 +01:00
Thomas Renger 510a56c16b Add (basic) editorconfig 2024-11-01 16:26:46 +01:00
Thomas Renger 5ae27d6000 Rafactor (rename part 2) 2024-11-01 12:01:47 +01:00
Thomas Renger f0cab8794c Refactoring (renaming) 2024-11-01 12:00:09 +01:00
Thomas Renger 3a6a0f86a3 Bump version to 1.1
All checks were successful
ci/woodpecker/push/docker Pipeline was successful
2024-11-01 11:16:17 +01:00
Thomas Renger e84aee17d5 Remove Matomo (Piwik) code
web analytics feel so obsolete
2024-11-01 11:15:37 +01:00
Thomas Renger de9c3a881c Secrets may not be passed as environment variables anymore.
All checks were successful
ci/woodpecker/push/docker Pipeline was successful
ci/woodpecker/manual/docker Pipeline was successful
2024-09-10 08:33:32 +02:00
Thomas Renger 0963e34707 Join both builds
Some checks failed
ci/woodpecker/push/docker Pipeline was successful
ci/woodpecker/manual/docker Pipeline failed
2024-09-07 17:47:01 +02:00
Thomas Renger cef8ee775e Sichelond
All checks were successful
ci/woodpecker/push/docker Pipeline was successful
(fixes #4 )
2024-09-07 17:04:50 +02:00
Thomas Renger b1a4fedbf6 Don’t put the Dockerfile into the container
All checks were successful
ci/woodpecker/push/docker Pipeline was successful
2024-09-04 17:55:36 +02:00
Thomas Renger a149d77461 Explicitly set Dockerfile location
All checks were successful
ci/woodpecker/manual/docker Pipeline was successful
2024-08-28 21:51:17 +02:00
Thomas Renger 80dff07d94 Maybe a docker build
Some checks failed
ci/woodpecker/manual/docker Pipeline failed
2024-08-28 21:45:31 +02:00
Thomas Renger f09544bbee First moon bot 2024-08-28 11:24:18 +02:00
8 changed files with 208 additions and 6 deletions

12
.editorconfig Normal file
View file

@ -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

2
.gitignore vendored
View file

@ -26,3 +26,5 @@
/vendors/*
.DS_Store
__pycache__
*.secret

View file

@ -1,9 +1,42 @@
pipeline:
docker-build:
secrets: [docker_username, docker_password]
steps:
build-bot:
image: woodpeckerci/plugin-docker-buildx
settings:
repo: dentaku/vollmond
tag: latest
username:
from_secret: docker_username
password:
from_secret: docker_password
context: bot
dockerfile: bot/Dockerfile
repo: dentaku/vollmond-bot
tags:
- latest
- v0.2
auto-tag: true
platforms: [linux/amd64, linux/arm64]
platforms: [linux/amd64, linux/arm64]
when:
- event: push
path:
include: [ 'bot/**' ]
- event: cron
- event: manual
build-webpage:
image: woodpeckerci/plugin-docker-buildx
settings:
username:
from_secret: docker_username
password:
from_secret: docker_password
repo: dentaku/vollmond
tags:
- latest
- v1.1
auto-tag: true
platforms: [linux/amd64, linux/arm64]
when:
- event: push
path:
include: [ 'wwwroot/**', 'Dockerfile' ]
- event: cron
- event: manual

2
bot/.dockerignore Normal file
View file

@ -0,0 +1,2 @@
*.secret
Dockerfile

9
bot/Dockerfile Normal file
View file

@ -0,0 +1,9 @@
FROM python:3
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD [ "python", "./bot.py" ]

23
bot/bot.py Normal file
View file

@ -0,0 +1,23 @@
import os
import moon
from mastodon import Mastodon
from pytz import timezone
from datetime import datetime
# Set up Mastodon
mastodon = Mastodon(
access_token = 'token.secret',
api_base_url = os.getenv('MASTODON_URL', 'https://mastodon.wazongtest.de/')
)
tz = timezone('Europe/Berlin')
now = datetime.now().astimezone(tz)
moon_text="Aktuelle Mondphase:\n"
moon_text+=moon.moon_phase_as_text(now)
print(moon_text)
mastodon.status_post(moon_text, visibility='unlisted')
me = mastodon.me()
print(mastodon.account_statuses(me['id'])[0])

119
bot/moon.py Normal file
View file

@ -0,0 +1,119 @@
import math
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'))
since2000 = (start - y2k) / 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 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
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
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
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 < 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):
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"))

2
bot/requirements.txt Normal file
View file

@ -0,0 +1,2 @@
Mastodon.py
pytz