-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.py
73 lines (61 loc) · 2.19 KB
/
cli.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import os
import typer
import pandas as pd
from Quackle import QuackleGame
app = typer.Typer(name="Multiplicative Persistence Explorer", add_completion=False)
# Delete bad files
@app.command()
def clean(
data_dir: str = typer.Option(
"data",
"--data-dir",
"-d",
help="The directory (and subdirectories) where we will search for malformed gcg files",
)
):
"""Delete incomplete gcg files"""
directories = [subdir for subdir, _, _ in os.walk(data_dir) if subdir != data_dir]
for directory in directories:
print("Looking for unfinished games in directory " + directory + "...")
errorFiles = []
for filename in os.listdir(directory):
if filename.endswith(".gcg"):
path = os.path.join(directory, filename)
if not QuackleGame.is_finished_game(path):
errorFiles.append(path)
if len(errorFiles) == 0:
print("All good! No unfinished games found")
else:
print("ERROR FILES")
for errorFile in errorFiles:
print("\t" + errorFile)
if input("Delete the files above? (Y/N)\n").lower() in ["yes", "y"]:
for errorFile in errorFiles:
os.unlink(errorFile)
print("Deletion complete")
else:
print("Deletion cancelled")
@app.command()
def generate_csvs(
data_dir: str = typer.Option(
"data",
"--data-dir",
"-d",
help="The directory where we will search for subdirectories and create a CSV file for those subdirectories",
)
):
"""Generate CSV files for all games in a subdirectory"""
directories = [subdir for subdir, _, _ in os.walk(data_dir) if subdir != data_dir]
for directory in directories:
print("Parsing games in directory " + directory + "...")
games = [
QuackleGame(os.path.join(directory, filename)).to_dict()
for filename in os.listdir(directory)
if filename.endswith(".gcg")
]
df = pd.DataFrame(games)
output_path = f"{directory}.csv"
print(f"Creating {output_path}...")
df.to_csv(output_path, index=False)
if __name__ == "__main__":
app()