def get_attendance_for_this_term(update, context): bot = context.bot hours, minutes = attendance_utils.get_attendance_for_this_term( update.message.chat_id) bot.send_message(update.message.chat_id, f"Your attendance:\n{hours} hours {minutes} minutes") menu(update, context)
def add_finish_time(update, context): bot = context.bot chat_data = context.chat_data date = update.message.text now = datetime.now() try: if date == "Now": date = now if date.hour >= 21: date += timedelta(days=1) date = date.replace(hour=(date.hour + 3) % 24, microsecond=0) date = str(date) else: date = str( datetime.strptime(date, '%H:%M').replace(year=now.year, month=chat_data['month'], day=chat_data['day'])) except Exception as e: bot.send_message(update.message.chat_id, "enter valid date and time and try again") return cancel(update, context) attendance_utils.add_attendance(str(update.message.chat_id), chat_data['start'], date) bot.send_message(update.message.chat_id, "saved") menu(update, context) return ConversationHandler.END
def get_attendance_for_period(update, context): bot = context.bot try: start, finish = update.message.text.split(":") now = datetime.now() if len(start.split("-")) == 3 and len(finish.split("-")) == 3: start = str(datetime.strptime(start, '%Y-%m-%d')) finish = str(datetime.strptime(finish, '%Y-%m-%d')) else: start = str( datetime.strptime(start, '%m-%d').replace(year=now.year)) finish = str( datetime.strptime(finish, '%m-%d').replace(year=now.year)) except: bot.send_message(update.message.chat_id, "enter valid date and time and try again") return cancel(update, context) hours, minutes = attendance_utils.get_attendance_for_period( update.message.chat_id, start, finish) bot.send_message(update.message.chat_id, f"Your attendance:\n{hours} hours {minutes} minutes") menu(update, context) return ConversationHandler.END
def cancel(update, context): menu(update, context) return ConversationHandler.END