ran6432 / look.py
WaterWorm's picture
Upload 3 files
2e2ea43 verified
import sqlite3
import pandas as pd
import os
# --- Configuration ---
db_path = r'c:\Users\xcool\Downloads\civitai\civitai.sqlite'
# --- THE IMPORTANT PART ---
# We add a WHERE clause to filter for the exact username we want.
# SQL strings are enclosed in single quotes (' ').
search_term = "direct22202"
query = "SELECT * FROM models WHERE username = '{search_term}';"
# --- Script Logic ---
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 by username '{search_term}'...")
df = pd.read_sql_query(query, conn)
if df.empty:
print("\nNo models found for that username.")
else:
# --- Option 1: Display results directly in the terminal ---
print("\n--- Found Models ---")
print(df)
# --- Option 2: Save results to a CSV file ---
df.to_csv(output_filename, index=False)
print(f"\n✅ Success! The results have also been saved to '{output_filename}'")
except Exception as e:
print(f"An error occurred: {e}")
finally:
if conn:
conn.close()
print("\nDatabase connection closed.")