Muthuraja18 commited on
Commit
9b345ce
·
verified ·
1 Parent(s): add7eb9
Files changed (1) hide show
  1. app.py +26 -0
app.py CHANGED
@@ -620,6 +620,32 @@ def create_game_page():
620
  st.info(f"AI questions will be generated for: {ai_topic}")
621
  # Here you can call your AI question generator function if you have one
622
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
623
 
624
  # 1️⃣ Define join_game first
625
  def join_game(game_id, username, avatar):
 
620
  st.info(f"AI questions will be generated for: {ai_topic}")
621
  # Here you can call your AI question generator function if you have one
622
 
623
+ def save_score_to_csv(row: dict):
624
+ import csv, os
625
+
626
+ file_exists = os.path.exists(LEADERBOARD_FILE)
627
+
628
+ with open(LEADERBOARD_FILE, "a", newline="", encoding="utf-8") as f:
629
+ writer = csv.DictWriter(
630
+ f,
631
+ fieldnames=[
632
+ "name",
633
+ "score",
634
+ "game_id",
635
+ "topics",
636
+ "timestamp",
637
+ "avatar",
638
+ "questions",
639
+ "answers",
640
+ "correct_flags",
641
+ ]
642
+ )
643
+
644
+ if not file_exists:
645
+ writer.writeheader()
646
+
647
+ writer.writerow(row)
648
+ f.flush() # 🔥 FORCE write
649
 
650
  # 1️⃣ Define join_game first
651
  def join_game(game_id, username, avatar):