def delete_content(update, context): log_id = context.user_data.get("log_id") conn = create_connection() work_content_id = select_record( conn, "logbook", ["work_content_id"], {"id": log_id} )[0][0] update_record(conn, "logbook", {"work_content_id": ""}, log_id) delete_record(conn, "contents", {"id": work_content_id}) return log_id
def put_location(location, user_data): """ docstring """ if location: conn = create_connection("db.sqlite3") record = {"longitude": location.longitude, "latitude": location.latitude} update_record(conn, "logbook", record, str(user_data.get("log_id"))) conn.close() return True return False
def post_remarks_by_log_ids(log_ids): conn = create_connection("db.sqlite3") (row,) = update_record(conn, "logbook", {"remarks": ""}, f"id IN ({log_ids})") conn.close() return row
def put_work_content(update, context, work_content, work_content_id): user = update.message.from_user record = { "chat_id": user.id, "first_name": user.first_name, "last_name": user.last_name, "timestamp": update.message.date.astimezone(pytz.timezone("Africa/Douala")), "work_content": work_content, } conn = create_connection() content_id = update_record(conn, "contents", record, work_content_id) logbook_record = {"work_content_id": content_id} update_record(conn, "logbook", logbook_record, context.user_data.get("log_id")) conn.close()
def start_edit(update, context): choices = {"YES": True, "NO": False} answer = choices.get(update.message.text) if answer: log_id = context.user_data.get("log_id") conn = create_connection() rows = select_record(conn, "logbook", ("category", "history"), {"id": log_id}) category = rows[0][0] history = rows[0][1] if rows[0][1] else "" history += f"Edited at {update.message.date} for {category}\n" update_record(conn, "logbook", {"history": history}, log_id) conn.close() keyboard_dict = { "signing in": [ ["Office", "Home"], ], "signing out": [[ "I worked at Office", "I would like to report because I worked at home", ]], "getting back": [ ["Without any member of KOICA", "With KOICA Colleagues"], ], } status_dict = { "signing in": "SIGN_IN", "signing out": "SIGN_OUT", "getting back": "GET_BACK", } context.user_data["status"] = status_dict.get(category) text_message = f"start to edit Log No.{log_id} by press button\n" reply_markdown(update, context, text_message, keyboard_dict.get(category)) else: text_message = "process has been stoped. The log has not been deleted." reply_markdown(update, context, text_message) context.user_data.clear() return ConversationHandler.END
def put_sub_category(log_id, sub_category): conn = create_connection("db.sqlite3") record = {"sub_category": sub_category} update_record(conn, "logbook", record, log_id) conn.close()
def put_confirmation(update, context): conn = create_connection() record = {"confirmation": "user confirmed"} update_record(conn, "logbook", record, context.user_data.get("log_id"))