def show_todos(update, context): text = context.args session = Session() include_done_tasks = '--all' in ' '.join(text) todos = session.query(Todo).filter_by(done=include_done_tasks).all() if not todos: msg = 'No pending todos' else: msg = '\n'.join(f"{todo.id}: {todo.text}" for todo in todos) update.message.reply_text(msg)
def expire_reminder(key): session = Session() reminder = session.query(Reminder).filter_by(key=key).first() if reminder is None: logger.info(f"Reminder {key!r} does not exist on db") expired = False else: reminder.expired = True session.commit() logger.info(f"Reminder {key!r} Expired") expired = True return expired
def mark_as_done(update, context): todo = context.args if not todo: update.message.reply_text('Missing todo id') return try: todo_id = int(todo[0]) except ValueError: update.message.reply_text('Todo id must be a digit') return s = Session() todo = s.query(Todo).filter_by(id=todo_id, done=False).first() if todo is None: msg = f'🚫 No pending todo with id`{todo_id}`' else: todo.done = True s.commit() msg = f"✅ Congratz. You've finished one todo" update.message.reply_markdown(msg)
def remove_reminder(text, **kwargs): session = Session() reminder = session.query(Reminder).filter_by(text=text, **kwargs).first() if reminder is None: logger.info(f"Reminder {text} does not exist on db") msg = f'🚫 El reminder `{text}` no existe en la base de datos' else: session.delete(reminder) logger.info(f"Reminder {text!r} DELETED") msg = f'✅ Reminder `{text}` borrado con éxito' session.commit() return msg
def add_todo(update, context): todo_text = context.args if not todo_text: msg = 'Usage: `/todo something`' else: try: todo = ' '.join(todo_text) session = Session() session.add(Todo(text=todo)) session.commit() msg = '✅ Saved' except Exception as e: msg = f'Error: {repr(e)}' update.message.reply_markdown(msg)
def add_reminder(reminder): session = Session() session.add(reminder) session.commit()
def get_reminders(order_attr=None, **kwargs): session = Session() return session.query(Reminder).filter_by(**kwargs).order_by(order_attr)