def command_save_list(user, chat_id, update_text): voc_list: models.List = get_user_list(user, 'created') if voc_list: voc_list.status = 'saved' add_notify_times(voc_list) send_message(chat_id, answers[update_text]['existed']) else: send_message(chat_id, answers[update_text]['not_existed'])
def notify(): now_time = datetime.datetime.now() lists = session.query(models.List, models.NotifyTime) \ .add_columns(models.User.t_id) \ .join(models.NotifyTime, models.List.id == models.NotifyTime.list_id) \ .join(models.User, models.User.id == models.List.user_id) \ .filter(models.NotifyTime.status == 'pending') \ .filter(models.List.status == 'saved') \ .filter(models.List.date == datetime.date.today()) \ .filter(models.NotifyTime.time.between( now_time - datetime.timedelta(minutes=2), now_time + datetime.timedelta(minutes=2))) lists = lists.all() for l in lists: words = '\n'.join(list(map(lambda w: f'[{w.word}]', l.List.words))) send_message(l.t_id, 'The today\'s list of the words:\n' + words) l.NotifyTime.status = 'completed' session.commit()
def command_new_list(user, chat_id, update_text): voc_list: models.List = get_user_list(user) if voc_list: if voc_list.status == 'created': send_message(chat_id, answers[update_text]['existed']['created']) if voc_list.status == 'saved': send_message(chat_id, answers[update_text]['existed']['saved']) else: user.lists.append(models.List(date=date.today())) send_message(chat_id, answers[update_text]['not_existed'])
def add_word(user, chat_id, update_text): voc_list: models.List = get_user_list(user, 'created') if voc_list: voc_list.words.append(models.Word(word=update_text)) send_message(chat_id, f'The new word [{update_text}] added to the list') else: voc_list: models.List = get_user_list(user, 'saved') if voc_list: send_message(chat_id, 'You\'ve already saved your today\'s list.') else: send_message(chat_id, 'There are no lists found for today\'s date. ' '\nYou can create the new one by typing the /new_list command!')
def command_get_list(user, chat_id, update_text): voc_list: models.List = get_user_list(user) if voc_list: words = '\n'.join(list(map(lambda w: f'[{w.word}]', voc_list.words))) send_message(chat_id, 'The today\'s list of the words:\n' + words)
def command_start(user, chat_id, update_text): if not user: session.add(models.User(t_id=chat_id)) send_message(chat_id, answers[update_text]['new_user']) else: send_message(chat_id, answers[update_text]['old_user'])
def command_get_commands(**kwargs): send_message(kwargs['chat_id'], answers[kwargs['update_text']])