diff --git a/homepage/participo/bdCheck.py b/homepage/participo/bdCheck.py index 66584ca..6a1567f 100644 --- a/homepage/participo/bdCheck.py +++ b/homepage/participo/bdCheck.py @@ -54,51 +54,48 @@ try: if t["gebDatum"] not in [None, "0000-00-00"] ] - MatrixIm.post( - message="last birthdays: \n" - + "\n".join( - [ - f"- {t['name']['given']} {t['name']['family']}: {get_days_since_birthday(t['date_of_birth'])} ({t['date_of_birth'].strftime('%d.%m.')})" - for t in sorted( - [ - t - for t in trainees - if get_days_since_birthday(t["date_of_birth"]) > -14 - ], - key=lambda t: get_days_since_birthday(t["date_of_birth"]), - ) - ] - ), - home_server_url="https://matrix.org", - room_id="!vFXxgKsLbRLdWCSTIO:matrix.org", - credentials={ - "user": "@ukenth-the-grumpy:matrix.org", - "password": "DQpSs1yn9Y26c1zo", - }, + last_birthday_kids = sorted( + [t for t in trainees if get_days_since_birthday(t["date_of_birth"]) > -14], + key=lambda t: get_days_since_birthday(t["date_of_birth"]), + ) + if last_birthday_kids: + MatrixIm.post( + message="last birthdays: \n" + + "\n".join( + [ + f"- {t['name']['given']} {t['name']['family']}: {get_days_since_birthday(t['date_of_birth'])} ({t['date_of_birth'].strftime('%d.%m.')})" + for t in last_birthday_kids + ] + ), + home_server_url="https://matrix.org", + room_id="!vFXxgKsLbRLdWCSTIO:matrix.org", + credentials={ + "user": "@ukenth-the-grumpy:matrix.org", + "password": "DQpSs1yn9Y26c1zo", + }, + ) + + next_birthday_kids = sorted( + [t for t in trainees if get_days_until_birthday(t["date_of_birth"]) < 14], + key=lambda t: get_days_until_birthday(t["date_of_birth"]), ) - MatrixIm.post( - message="next birthdays: \n" - + "\n".join( - [ - f"- {t['name']['given']} {t['name']['family']}: {get_days_until_birthday(t['date_of_birth'])} ({t['date_of_birth'].strftime('%d.%m.')})" - for t in sorted( - [ - t - for t in trainees - if get_days_until_birthday(t["date_of_birth"]) < 14 - ], - key=lambda t: get_days_until_birthday(t["date_of_birth"]), - ) - ] - ), - home_server_url="https://matrix.org", - room_id="!vFXxgKsLbRLdWCSTIO:matrix.org", - credentials={ - "user": "@ukenth-the-grumpy:matrix.org", - "password": "DQpSs1yn9Y26c1zo", - }, - ) + if next_birthday_kids: + MatrixIm.post( + message="next birthdays: \n" + + "\n".join( + [ + f"- {t['name']['given']} {t['name']['family']}: {get_days_until_birthday(t['date_of_birth'])} ({t['date_of_birth'].strftime('%d.%m.')})" + for t in next_birthday_kids + ] + ), + home_server_url="https://matrix.org", + room_id="!vFXxgKsLbRLdWCSTIO:matrix.org", + credentials={ + "user": "@ukenth-the-grumpy:matrix.org", + "password": "DQpSs1yn9Y26c1zo", + }, + ) except Exception as e: MatrixIm.post( message=f"bdCheck: Exception {e} ({repr(e)})\nResponse was {response}",