-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseedSupabase.py
More file actions
48 lines (38 loc) · 1.58 KB
/
seedSupabase.py
File metadata and controls
48 lines (38 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import psycopg2
import os
RAW_URL = os.environ.get("DATABASE_URL", "postgresql://postgres.mtbsgadocmnhjxxdnmdj:Ei4IvmIAjsU5lXra@aws-1-ap-southeast-1.pooler.supabase.com:6543/postgres")
DATABASE_URL = RAW_URL if "?" in RAW_URL else f"{RAW_URL}?sslmode=require"
def seed_to_supabase():
IMAGE_DIR = "static/images"
try:
conn = psycopg2.connect(DATABASE_URL)
cur = conn.cursor()
cur.execute("""
CREATE TABLE IF NOT EXISTS girls (
id SERIAL PRIMARY KEY,
filename VARCHAR(255) UNIQUE NOT NULL,
elo INTEGER NOT NULL DEFAULT 1500
);
""")
images = [f for f in os.listdir(IMAGE_DIR) if f.lower().endswith('.webp')]
print(f"📂 Found {len(images)} local images. Checking database...")
cur.execute("SELECT filename FROM girls;")
existing = {row[0] for row in cur.fetchall()}
new_count = 0
for img in images:
if img not in existing:
cur.execute(
"INSERT INTO girls (filename, elo) VALUES (%s, %s)",
(img, 1500)
)
print(f"➕ Added new: {img}")
new_count += 1
conn.commit()
print(f"✅ Sync complete! Added {new_count} new images. {len(existing)} veterans remain untouched.")
except Exception as e:
print(f"❌ Error: {e}")
finally:
if 'cur' in locals(): cur.close()
if 'conn' in locals(): conn.close()
if __name__ == "__main__":
seed_to_supabase()