File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44import sys
55import csv
66import 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
817if len (sys .argv ) != 2 :
918 print ("Please call the script as follows" )
1019 print ("python3 csv2mad.py ARCADE_METADATA_FILE(.csv)" )
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 ( "&" , "&" ) , '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
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 } /" )
You can’t perform that action at this time.
0 commit comments