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() | |