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

Bugfix: next - Days +1 to fix <48h Issue and modified birthday tomorrow text

parent e8c23ccb
No related branches found
No related tags found
No related merge requests found
......@@ -26,12 +26,11 @@ class Birthday:
# comp = splittedDateSelf[1].__cmp__(splittedDateOther[1]) # compare month
# if comp == 0:
# comp = splittedDateSelf[0].__cmp__(splittedDateOther[0]) # compare day
## if comp == 0:
# if comp == 0:
# comp = self.PERSON.__cmp__(other.PERSON) # compare name
#
# return comp
def get_congratulation(self):
return f"Alles Gute {self.PERSON}"
......@@ -80,7 +79,8 @@ class ModuleBirthdayReminder:
if dm == birthday.DATE:
for group in self.GROUPS:
if group["NAME"] == key:
self.send(birthday.get_congratulation(), group["ID"])
self.send(
birthday.get_congratulation(), group["ID"])
break
def get_next_birthday(self, groupInfo):
......@@ -93,7 +93,8 @@ class ModuleBirthdayReminder:
# Dieses Jahr
birthday_string = f"{birthday.DATE}.{date.today().strftime('%Y')}"
birthday_dt = datetime.strptime(birthday_string, format)
delta_temp = (birthday_dt - today).days
delta_temp = (birthday_dt - today).days + 1 # Damit er bei 47h nicht 1 Tag sagt
if 0 < delta_temp < delta:
next_birthday = birthday
delta = delta_temp
......@@ -101,13 +102,18 @@ class ModuleBirthdayReminder:
# Nächstes Jahr (Für den Jahresüberlauf)
next_year = date.today() + relativedelta(years=1)
birthday_next_year_string = f"{birthday.DATE}.{next_year.strftime('%Y')}"
birthday_next_year = datetime.strptime(birthday_next_year_string, format)
delta_temp = (birthday_next_year - today).days
birthday_next_year = datetime.strptime(
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
delta = delta_temp
message = "Niemand hat hier Geburtstag! Wir sind in einer Zeitschleife gefangen."
if next_birthday:
if delta == 1:
message = f"Morgen hat {next_birthday.PERSON} Geburtstag!🎉"
else:
message = f"Als nächstes hat {next_birthday.PERSON} am {next_birthday.DATE} Geburtstag (noch {delta} Tage)"
return message
......@@ -123,20 +129,24 @@ class ModuleBirthdayReminder:
def interpret_birthday_line(self, line):
splitted = line.strip().split(",")
if len(splitted) != 2:
raise SyntaxError("Invalid birthday syntax! Needs to be: person, date(Day.Month) eg.: Karl, 02.09")
raise SyntaxError(
"Invalid birthday syntax! Needs to be: person, date(Day.Month) eg.: Karl, 02.09")
person = splitted[0].strip()
if len(person) == 0:
raise SyntaxError("No name given! Needs to be: person, date(Day.Month) eg.: Karl, 02.09")
raise SyntaxError(
"No name given! Needs to be: person, date(Day.Month) eg.: Karl, 02.09")
splittedDate = splitted[1].strip().split(".")
if len(splitted) != 2:
raise SyntaxError("Invalid date! Needs to be: person, date(Day.Month) eg.: Karl, 02.09")
raise SyntaxError(
"Invalid date! Needs to be: person, date(Day.Month) eg.: Karl, 02.09")
day = splittedDate[0].strip()
month = splittedDate[1].strip()
if len(day) > 2 or len(month) > 2 or len(day) == 0 or len(month) == 0:
raise SyntaxError("Invalid date! Needs to be: person, date(Day.Month) eg.: Karl, 02.09")
raise SyntaxError(
"Invalid date! Needs to be: person, date(Day.Month) eg.: Karl, 02.09")
if len(day) == 1:
day = f"0{day}"
if len(month) == 1:
......@@ -155,7 +165,8 @@ class ModuleBirthdayReminder:
self.birthday_list[groupInfo["NAME"]].append(birthday)
except (SyntaxError, ValueError) as exc:
self.log.warning(f"{self.tag}Error while interpreting birthday line:{message}; Error: {exc}")
self.log.warning(
f"{self.tag}Error while interpreting birthday line:{message}; Error: {exc}")
return f"{exc}"
try:
......@@ -163,5 +174,6 @@ class ModuleBirthdayReminder:
f.write(f"{birthday.get_csv_line()}\n")
return "Successfully added birthday"
except IOError as exc:
self.log.error(f"{self.tag}Adding new birthday'{birthday.get_csv_line()}' to file failed: {exc}")
self.log.error(
f"{self.tag}Adding new birthday'{birthday.get_csv_line()}' to file failed: {exc}")
return "Saving birthday failed"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment