Browse Source

Osterberechnung als SupyBot-Plugin Holidays

master
qwertfisch 1 year ago
commit
0a02736837
  1. 24
      Holidays/__init__.py
  2. 18
      Holidays/config.py
  3. 60
      Holidays/plugin.py
  4. 0
      Holidays/test.py
  5. 35
      holidays.py

24
Holidays/__init__.py

@ -0,0 +1,24 @@
import supybot
import supybot.world as world
# Use this for the version of this plugin. You may wish to put a CVS keyword
# in here if you\'re keeping the plugin in CVS or some similar system.
__version__ = "%%VERSION%%"
__author__ = "qwertfisch"
__maintainer__ = ""
# This is a dictionary mapping supybot.Author instances to lists of
# contributions.
__contributors__ = {}
from . import config
from . import plugin
from importlib import reload
reload(plugin) # In case we're being reloaded.
if world.testing:
from . import test
Class = plugin.Class
configure = config.configure

18
Holidays/config.py

@ -0,0 +1,18 @@
import supybot.conf as conf
import supybot.registry as registry
from supybot.i18n import PluginInternationalization, internationalizeDocstring
_ = PluginInternationalization('Holidays')
def configure(advanced):
# This will be called by supybot to configure this module. advanced is
# a bool that specifies whether the user identified themself as an advanced
# user or not. You should effect your configuration by manipulating the
# registry as appropriate.
from supybot.questions import expect, anything, something, yn
conf.registerPlugin('Holidays', True)
Holidays = conf.registerPlugin('Holidays')
# This is where your configuration variables (if any) should go. For example:
# conf.registerGlobalValue(Holidays, 'someConfigVariableName',
# registry.Boolean(False, _("""Help for someConfigVariableName.""")))

60
Holidays/plugin.py

@ -0,0 +1,60 @@
from datetime import date
import supybot.utils as utils
from supybot.commands import *
import supybot.ircutils as ircutils
import supybot.callbacks as callbacks
from supybot import commands
from supybot.i18n import PluginInternationalization, internationalizeDocstring
_ = PluginInternationalization('Holidays')
class Holidays(callbacks.Plugin):
"""This plugin calculates and returns the number of days until the next given holiday,
like Eastern, Christmas etc."""
def __init__(self, irc):
self.__parent = super(Holidays, self)
self.__parent.__init__(irc)
def easter(year):
a = year % 19
b = year % 4
c = year % 7
k = year // 100
p = k // 3
q = k // 4
M = (15 + k - p - q) % 30
d = (19*a + M) % 30
N = (4 + k - q) % 7
e = (2*b + 4*c + 6*d + N) % 7
easter_date = 22 + d + e
if easter_date > 31:
return date(year, 4, easter_date - 31)
else:
return date(year, 3, easter_date)
@internationalizeDocstring
def holiday(self, irc, msg, args, holiday_name):
"""[<holiday name>]
Returns the number of days until the next given holiday.
"""
if holiday_name.lower() != 'ostern':
irc.reply('Tut mir leid, ich beherrsche nur Ostern.')
return
# Determine Easter date for current year
easter_current_year = easter(date.today().year)
days_remaining = (easter_current_year - date.today()).days
# If it has already passed, determine date for next year
if days_remaining < 0:
easter_next_year = easter(date.today().year + 1)
days_remaining = (easter_next_year - date.today()).days
if days_remaining == 0:
irc.reply('Heute ist Ostersonntag.')
else:
irc.reply(f'Es sind noch {days_remaining} Tage bis Ostersonntag.')
holiday = wrap(holiday, ['text'])

0
Holidays/test.py

35
holidays.py

@ -0,0 +1,35 @@
# Calculation how many days to next Easter sunday
import sys
from datetime import date
def easter(year):
a = year % 19
b = year % 4
c = year % 7
k = year // 100
p = k // 3
q = k // 4
M = (15 + k - p - q) % 30
d = (19*a + M) % 30
N = (4 + k - q) % 7
e = (2*b + 4*c + 6*d + N) % 7
easter_date = 22 + d + e
if easter_date > 31:
return date(year, 4, easter_date - 31)
else:
return date(year, 3, easter_date)
# Determine Easter date for current year
easter_current_year = easter(date.today().year)
days_remaining = (easter_current_year - date.today()).days
# If it has already passed, determine date for next year
if days_remaining < 0:
easter_next_year = easter(date.today().year + 1)
days_remaining = (easter_next_year - date.today()).days
if days_remaining == 0:
print("juhu, ostersonntag!")
else:
print(f"Noch {days_remaining} Tage bis Ostersonntag!")
Loading…
Cancel
Save