| import sqlite3
|
| import pandas as pd
|
| import os
|
|
|
|
|
| db_path = r'c:\Users\xcool\Downloads\civitai\civitai.sqlite'
|
|
|
|
|
|
|
| search_term = "Donald trump"
|
|
|
|
|
|
|
|
|
| query = "SELECT id, name, type, username FROM models WHERE name LIKE ?;"
|
|
|
|
|
| output_filename = f'search_results_for_{search_term}.csv'
|
|
|
| if not os.path.exists(db_path):
|
| print(f"Error: The file was not found at the path: {db_path}")
|
| else:
|
| conn = None
|
| try:
|
| conn = sqlite3.connect(db_path)
|
| print(f"Successfully connected. Searching for models with '{search_term}' in the name...")
|
|
|
|
|
|
|
| df = pd.read_sql_query(query, conn, params=(f'%{search_term}%',))
|
|
|
| if df.empty:
|
| print(f"\nNo models found matching '{search_term}'.")
|
| else:
|
| print(f"\n--- Found {len(df)} Matching Models ---")
|
|
|
| print(df)
|
|
|
|
|
| df.to_csv(output_filename, index=False)
|
| print(f"\n✅ Success! The results have been saved to '{output_filename}'")
|
|
|
| except Exception as e:
|
| print(f"An error occurred: {e}")
|
| finally:
|
| if conn:
|
| conn.close()
|
| print("\nDatabase connection closed.") |