-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Python instead of Excel for sorting map CSVs
- Loading branch information
1 parent
4670e96
commit e1e53ad
Showing
3 changed files
with
54 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
import sys | ||
import glob | ||
import csv | ||
|
||
|
||
maps_dir = os.path.split(sys.argv[0])[:-1][0] | ||
csv_files = glob.glob(os.path.join(maps_dir, "*.csv")) | ||
|
||
|
||
def sort_csv(filepath, column=0): | ||
with open(filepath, mode="r", newline="") as infile: | ||
reader = csv.reader(infile) | ||
header = next(reader) | ||
sorted_rows = sorted(reader, key=lambda row: row[column]) | ||
|
||
with open(filepath, mode="w", newline="\n") as outfile: | ||
writer = csv.writer(outfile) | ||
writer.writerow(header) | ||
writer.writerows(sorted_rows) | ||
|
||
|
||
for csv_file in csv_files: | ||
sort_csv(csv_file) |