Spaces:
Running
Running
Update mtdna_backend.py
Browse files- mtdna_backend.py +18 -3
mtdna_backend.py
CHANGED
@@ -615,14 +615,29 @@ def load_user_usage():
|
|
615 |
data = sheet.get_all_values()
|
616 |
|
617 |
if not data or len(data) < 2:
|
|
|
618 |
return {}
|
619 |
|
620 |
-
|
621 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
622 |
return usage
|
623 |
|
624 |
except Exception as e:
|
625 |
-
print(f"
|
626 |
return {}
|
627 |
|
628 |
|
|
|
615 |
data = sheet.get_all_values()
|
616 |
|
617 |
if not data or len(data) < 2:
|
618 |
+
print("⚠️ Sheet is empty or missing rows.")
|
619 |
return {}
|
620 |
|
621 |
+
headers = [h.strip().lower() for h in data[0]]
|
622 |
+
if "email" not in headers or "usage_count" not in headers:
|
623 |
+
print("❌ Header format incorrect. Must have 'email' and 'usage_count'.")
|
624 |
+
return {}
|
625 |
+
|
626 |
+
df = pd.DataFrame(data[1:], columns=headers)
|
627 |
+
|
628 |
+
usage = {}
|
629 |
+
for _, row in df.iterrows():
|
630 |
+
email = row.get("email", "").strip().lower()
|
631 |
+
try:
|
632 |
+
count = int(row.get("usage_count", 0))
|
633 |
+
if email:
|
634 |
+
usage[email] = count
|
635 |
+
except ValueError:
|
636 |
+
print(f"⚠️ Invalid usage_count for {email}: {row.get('usage_count')}")
|
637 |
return usage
|
638 |
|
639 |
except Exception as e:
|
640 |
+
print(f"❌ Error in load_user_usage: {e}")
|
641 |
return {}
|
642 |
|
643 |
|