Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/quiz_admin/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import asyncio
import json
import string
import sys
from pathlib import Path
from typing import Any
Expand Down Expand Up @@ -43,7 +44,18 @@ async def receive_messages(ws: ClientConnection) -> None:
"""Receive messages from the server and print them to the console."""
while True:
response = await ws.recv()
print(response)
try:
message = json.loads(response)
print_question(message)
except (TypeError, json.JSONDecodeError):
print(response)
Comment thread
JanaDrazkova marked this conversation as resolved.


def print_question(question: dict[str, list | str]) -> None:
"""Nicely print text of the question with possible answers."""
print(f"Question: {question['text']}")
for letter, opt in zip(string.ascii_letters, question["options"], strict=False):
print(f"\t{letter}) {opt}")


def main() -> None:
Expand Down
Loading