-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_data.py
More file actions
21 lines (18 loc) · 706 Bytes
/
get_data.py
File metadata and controls
21 lines (18 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import os
import pandas as pd
from src.generate import generate_puzzle
def get_data(n):
# Check if the CSV file already exists
csv_file = 'data/puzzles.csv'
if os.path.exists(csv_file):
# Read existing puzzles from the CSV file
df = pd.read_csv(csv_file)
else:
# If the file doesn't exist, start with an empty DataFrame
df = pd.DataFrame(columns=['quizzes', 'solutions'])
# Generate and append new puzzles to the DataFrame
for _ in range(n):
solution, puzzle = generate_puzzle(False)
df = df._append({'quizzes': puzzle, 'solutions': solution}, ignore_index=True)
# Save puzzles to CSV file
df.to_csv(csv_file, index=False)