File size: 814 Bytes
1b8aef5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import json
import requests
from app import DEFAULT_API_URL
def main() -> None:
api_url = DEFAULT_API_URL
questions_url = f"{api_url}/questions"
dest_file = "data/questions.jsonl"
try:
response = requests.get(questions_url, timeout=15)
response.raise_for_status()
questions_data = response.json()
if not questions_data:
print("Fetched questions list is empty.")
return
print(f"Fetched {len(questions_data)} questions.")
except requests.exceptions.RequestException as e:
print(f"Error fetching questions: {e}")
return
with open(dest_file, mode="w") as f:
for item in questions_data:
json.dump(item, f)
f.write("\n")
print("Done.")
if __name__ == "__main__":
main()
|