Skip to content
Snippets Groups Projects
Commit 82935150 authored by Frederic Aust's avatar Frederic Aust
Browse files

Wenn als nächstes mehr als eine Person am selben Tag Geburtstag haben wird nun...

Wenn als nächstes mehr als eine Person am selben Tag Geburtstag haben wird nun auf bei de aufmerksam gemacht / gratuliert
parent eaa1242a
Branches
No related tags found
No related merge requests found
...@@ -86,7 +86,8 @@ class ModuleBirthdayReminder: ...@@ -86,7 +86,8 @@ class ModuleBirthdayReminder:
today = datetime.today() today = datetime.today()
format = "%d.%m.%Y" format = "%d.%m.%Y"
delta = 800 delta = 800
next_birthday = None next_birthdays=[]
next_birthday_date = None
birthday_next_year_string = "" birthday_next_year_string = ""
for birthday in self.birthday_list[groupInfo["NAME"]]: for birthday in self.birthday_list[groupInfo["NAME"]]:
# Dieses Jahr # Dieses Jahr
...@@ -95,7 +96,7 @@ class ModuleBirthdayReminder: ...@@ -95,7 +96,7 @@ class ModuleBirthdayReminder:
delta_temp = (birthday_dt - today).days + 1 # Damit er bei 47h nicht 1 Tag sagt delta_temp = (birthday_dt - today).days + 1 # Damit er bei 47h nicht 1 Tag sagt
if 0 < delta_temp < delta: if 0 < delta_temp < delta:
next_birthday = birthday next_birthday_date = birthday_dt
delta = delta_temp delta = delta_temp
else: else:
# Nächstes Jahr (Für den Jahresüberlauf) # Nächstes Jahr (Für den Jahresüberlauf)
...@@ -105,15 +106,36 @@ class ModuleBirthdayReminder: ...@@ -105,15 +106,36 @@ class ModuleBirthdayReminder:
birthday_next_year_string, format) birthday_next_year_string, format)
delta_temp = (birthday_next_year - today).days + 1 # Damit er bei 47h nicht 1 Tag sagt delta_temp = (birthday_next_year - today).days + 1 # Damit er bei 47h nicht 1 Tag sagt
if delta_temp < delta: if delta_temp < delta:
next_birthday = birthday next_birthday_date = birthday_dt
delta = delta_temp delta = delta_temp
message = "Niemand hat hier Geburtstag! Wir sind in einer Zeitschleife gefangen." 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: 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: 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 return message
def get_birthdaylist(self, groupInfo): def get_birthdaylist(self, groupInfo):
......
...@@ -6,7 +6,8 @@ import json ...@@ -6,7 +6,8 @@ import json
import logging import logging
import random import random
import time import time
from datetime import date, calendar import calendar
from datetime import date
from threading import Thread from threading import Thread
import paho.mqtt.client as mqtt # EPL V1.0 import paho.mqtt.client as mqtt # EPL V1.0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment