Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -298,7 +298,6 @@ with gr.Blocks() as interface:
|
|
298 |
import uuid
|
299 |
|
300 |
timestamp = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC")
|
301 |
-
|
302 |
if not email.strip():
|
303 |
email = f"anonymous_{str(uuid.uuid4())[:8]}"
|
304 |
|
@@ -315,17 +314,22 @@ with gr.Blocks() as interface:
|
|
315 |
headers = data[0]
|
316 |
email_col = headers.index("email")
|
317 |
samples_col = headers.index("samples")
|
318 |
-
recent_time_col = headers.index("recent_time
|
319 |
|
320 |
-
# Find
|
321 |
-
for i, row in enumerate(data[1:], start=2): # start=2
|
322 |
if row[email_col].strip().lower() == email.strip().lower():
|
323 |
-
|
|
|
|
|
|
|
|
|
|
|
324 |
worksheet.update_cell(i, recent_time_col + 1, timestamp)
|
325 |
print(f"✅ Updated existing user row for: {email}")
|
326 |
return
|
327 |
|
328 |
-
# If email not found,
|
329 |
new_row = [""] * len(headers)
|
330 |
new_row[email_col] = email
|
331 |
new_row[samples_col] = ", ".join(samples)
|
|
|
298 |
import uuid
|
299 |
|
300 |
timestamp = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC")
|
|
|
301 |
if not email.strip():
|
302 |
email = f"anonymous_{str(uuid.uuid4())[:8]}"
|
303 |
|
|
|
314 |
headers = data[0]
|
315 |
email_col = headers.index("email")
|
316 |
samples_col = headers.index("samples")
|
317 |
+
recent_time_col = headers.index("recent_time")
|
318 |
|
319 |
+
# Step 1: Find row matching the email
|
320 |
+
for i, row in enumerate(data[1:], start=2): # start=2 for correct row indexing
|
321 |
if row[email_col].strip().lower() == email.strip().lower():
|
322 |
+
old_samples = row[samples_col].strip() if len(row) > samples_col else ""
|
323 |
+
old_sample_list = [s.strip() for s in old_samples.split(",") if s.strip()]
|
324 |
+
all_samples = list(dict.fromkeys(old_sample_list + samples)) # deduplicate while preserving order
|
325 |
+
new_sample_string = ", ".join(all_samples)
|
326 |
+
|
327 |
+
worksheet.update_cell(i, samples_col + 1, new_sample_string)
|
328 |
worksheet.update_cell(i, recent_time_col + 1, timestamp)
|
329 |
print(f"✅ Updated existing user row for: {email}")
|
330 |
return
|
331 |
|
332 |
+
# Step 2: If email not found, add new row
|
333 |
new_row = [""] * len(headers)
|
334 |
new_row[email_col] = email
|
335 |
new_row[samples_col] = ", ".join(samples)
|