Spaces:
Running
Running
Update app.py (#103)
Browse files- Update app.py (0e1e68a02a7227f01401fb8f7b19100d94383d8c)
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):
|