-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport_to_supabase.py
47 lines (35 loc) · 1.36 KB
/
import_to_supabase.py
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
import json
from supabase import create_client
import os
from dotenv import load_dotenv
import time
# Load environment variables
load_dotenv()
# Initialize Supabase client
supabase_url = os.getenv('SUPABASE_URL')
supabase_key = os.getenv('SUPABASE_KEY')
if not supabase_url or not supabase_key:
raise ValueError("Please set SUPABASE_URL and SUPABASE_KEY in your .env file")
supabase = create_client(supabase_url, supabase_key)
def import_data():
# Load the generated data
with open('simulated_igt_data.json', 'r') as f:
data = json.load(f)
print(f"Loaded {len(data)} participants to import")
# Import in batches to avoid timeouts
batch_size = 10
total_imported = 0
for i in range(0, len(data), batch_size):
batch = data[i:i+batch_size]
try:
result = supabase.table('participants').insert(batch).execute()
total_imported += len(batch)
print(f"Imported batch {i//batch_size + 1}, total progress: {total_imported}/{len(data)}")
# Small delay to avoid rate limits
time.sleep(1)
except Exception as e:
print(f"Error importing batch starting at index {i}: {str(e)}")
continue
print(f"\nImport complete. Total records imported: {total_imported}")
if __name__ == "__main__":
import_data()