from datetime import datetime from os import fsdecode, listdir, sep from modules.utils import configGet, jsonLoad, locale from dateutil.relativedelta import relativedelta def check_birthdays(app): for user_file in listdir(f"{configGet('data', 'locations')}{sep}users{sep}"): filename = fsdecode(f"{configGet('data', 'locations')}{sep}users{sep}{user_file}") if filename.endswith(".json"): user = jsonLoad(filename) if isinstance(user["application"]["2"], str): try: if ".".join([((user["application"]["2"]).split("."))[0], ((user["application"]["2"]).split("."))[1]]) == datetime.now().strftime("%d.%m"): tg_user = app.get_users(int(user_file.replace(".json", ""))) app.send_message( configGet("admin_group"), locale("birthday", "message").format(str(tg_user.first_name), str(tg_user.username), str(relativedelta(datetime.now(), datetime.strptime(user["application"]["2"], '%d.%m.%Y')).years)) ) except AttributeError: continue