Skip to content

Commit 83a237b

Browse files
authored
Update python scrip to be agnostic. Might revert
1 parent ba8a322 commit 83a237b

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

csv2mad.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@
44
import sys
55
import csv
66
import tqdm
7+
import re
78

9+
# Function to clean up filenames
10+
def sanitize_filename(name):
11+
name = name.replace("&", "&") # Convert HTML entity
12+
name = name.replace(":", " -") # Replace colon with dash/space
13+
name = re.sub(r'[<>:"/\\|?*\n\r]', '', name) # Remove invalid characters
14+
return name.strip()
15+
16+
# Check script usage
817
if len(sys.argv) != 2:
918
print("Please call the script as follows")
1019
print("python3 csv2mad.py ARCADE_METADATA_FILE(.csv)")
@@ -23,9 +32,12 @@
2332
next(csv_reader) # Skip header row
2433

2534
for game in tqdm.tqdm(csv_reader, desc="Generating mads", total=total_rows):
26-
mad_filename = os.path.join(OUTPUT_DIR, game[MAD_NAME_COLUMN] + ".mad")
35+
mad_filename = os.path.join(
36+
OUTPUT_DIR,
37+
sanitize_filename(game[MAD_NAME_COLUMN]).lower() + ".mad"
38+
)
2739

28-
with open(mad_filename.replace("&amp;", "&"), 'w') as f:
40+
with open(mad_filename, 'w') as f:
2941
f.write("<?xml version=\"1.0\" ?>\n")
3042
f.write("<misterarcadedescription>\n\n")
3143

@@ -50,4 +62,4 @@
5062

5163
f.write("</misterarcadedescription>")
5264

53-
print(f"MADs have been generated in folder {OUTPUT_DIR}/")
65+
print(f"MADs have been generated in folder {OUTPUT_DIR}/")

0 commit comments

Comments
 (0)