From 82935150828708b30874b2a10f3e7f6b6f03dc59 Mon Sep 17 00:00:00 2001 From: Frederic Aust <frederic.aust@stud.hs-bochum.de> Date: Mon, 26 Sep 2022 12:01:37 +0200 Subject: [PATCH] =?UTF-8?q?Wenn=20als=20n=C3=A4chstes=20mehr=20als=20eine?= =?UTF-8?q?=20Person=20am=20selben=20Tag=20Geburtstag=20haben=20wird=20nun?= =?UTF-8?q?=20auf=20bei=20de=20aufmerksam=20gemacht=20/=20gratuliert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mod_birthdayreminder.py | 34 ++++++++++++++++++++++++++++------ signalbot.py | 3 ++- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/mod_birthdayreminder.py b/mod_birthdayreminder.py index 95bccb7..ac905fe 100644 --- a/mod_birthdayreminder.py +++ b/mod_birthdayreminder.py @@ -86,7 +86,8 @@ class ModuleBirthdayReminder: today = datetime.today() format = "%d.%m.%Y" delta = 800 - next_birthday = None + next_birthdays=[] + next_birthday_date = None birthday_next_year_string = "" for birthday in self.birthday_list[groupInfo["NAME"]]: # Dieses Jahr @@ -95,7 +96,7 @@ class ModuleBirthdayReminder: delta_temp = (birthday_dt - today).days + 1 # Damit er bei 47h nicht 1 Tag sagt if 0 < delta_temp < delta: - next_birthday = birthday + next_birthday_date = birthday_dt delta = delta_temp else: # Nächstes Jahr (Für den Jahresüberlauf) @@ -105,15 +106,36 @@ class ModuleBirthdayReminder: birthday_next_year_string, format) delta_temp = (birthday_next_year - today).days + 1 # Damit er bei 47h nicht 1 Tag sagt if delta_temp < delta: - next_birthday = birthday + next_birthday_date = birthday_dt delta = delta_temp message = "Niemand hat hier Geburtstag! Wir sind in einer Zeitschleife gefangen." - if next_birthday: + if next_birthday_date: + for birthday in self.birthday_list[groupInfo["NAME"]]: + # Dieses Jahr + birthday_string = f"{birthday.DATE}.{date.today().strftime('%Y')}" + birthday_dt = datetime.strptime(birthday_string, format) + + if birthday_dt == next_birthday_date: + next_birthdays.append(birthday) + if delta == 1: - message = f"Morgen hat {next_birthday.PERSON} Geburtstag!🎉" + message = f"Morgen hat{next_birthdays[0].PERSON} Geburtstag!🎉" + if(len(next_birthdays)>1): + message=f"Morgen haben" + for birthday in next_birthdays: + message+=f" {birthday.PERSON} und" + message = message[:-4] + message+=" Geburtstag!🎉" else: - message = f"Als nächstes hat {next_birthday.PERSON} am {next_birthday.DATE} Geburtstag (noch {delta} Tage)" + message = f"Als nächstes hat {next_birthdays.PERSON} am {next_birthdays.DATE} Geburtstag (noch {delta} Tage)" + + if(len(next_birthdays)>1): + message=f"Als nächstes haben" + for birthday in next_birthdays: + message+=f" {birthday.PERSON} und" + message = message[:-4] + message+=" am {next_birthdays.DATE} Geburtstag (noch {delta} Tage)" return message def get_birthdaylist(self, groupInfo): diff --git a/signalbot.py b/signalbot.py index 37858e0..b43c2d8 100755 --- a/signalbot.py +++ b/signalbot.py @@ -6,7 +6,8 @@ import json import logging import random import time -from datetime import date, calendar +import calendar +from datetime import date from threading import Thread import paho.mqtt.client as mqtt # EPL V1.0 -- GitLab