import pymysql # Database connection DB_CONFIG = { "host": "rm-f8ze60yirdj8786u2wo.mysql.rds.aliyuncs.com", "user": "root", "password": "csqz@20255", "db": "csqz-client", "charset": "utf8mb4", "cursorclass": pymysql.cursors.DictCursor } def add_existing_pdf(): """Add existing PDF to genealogy_pdfs table""" conn = pymysql.connect(**DB_CONFIG) try: with conn.cursor() as cursor: # Check if the PDF already exists cursor.execute("SELECT * FROM genealogy_pdfs WHERE file_name LIKE %s", ("%留总-正式-卷四齿录%",)) existing = cursor.fetchone() if existing: print("PDF already exists in the database") return # Add the PDF entry pdf_file_name = "留总-正式-卷四齿录_留总收藏.pdf" # Create a placeholder URL based on the image URLs placeholder_url = "https://file.chunsunqiuzhu.com/data/2026/03/31/留总-正式-卷四齿录_留总收藏.pdf" uploader = "留总" cursor.execute( "INSERT INTO genealogy_pdfs (file_name, oss_url, uploader) VALUES (%s, %s, %s)", (pdf_file_name, placeholder_url, uploader) ) conn.commit() print(f"PDF '{pdf_file_name}' added to genealogy_pdfs table") except Exception as e: print(f"Error: {e}") conn.rollback() finally: conn.close() if __name__ == "__main__": add_existing_pdf()