-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_parser.py
More file actions
33 lines (22 loc) · 866 Bytes
/
command_parser.py
File metadata and controls
33 lines (22 loc) · 866 Bytes
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
import sys
if len(sys.argv[1::]) == 0:
print("No input file given!")
exit(1)
if not ".csv" in sys.argv[1]:
print("Invalid or missing file type! (Must be .csv)")
exit(1)
print(f"--- Parsing '{sys.argv[1]}'")
out = open("commands.txt", "w", encoding="utf8")
with open(sys.argv[1], "r", encoding="utf8") as f:
for i, line in enumerate(f):
if i == 0: continue #Ignore first row
line = line.strip().split(",")[8:12] #Get middle 4 rows
if line[0] == "" or line[1] == "": continue #Skip if no command in line
line[3] = "0" if line[3] == "-" or line[3] == "-" else "1" #Set argument requirement
print(f"{i:02d}: {line}")
out.write(line[1].lower() + " ")
out.write(line[0] + " ")
out.write(line[3] + " ")
out.write("\n")
print("--- File saved as commands.txt")
out.close()