Created
April 22, 2023 00:13
-
-
Save JasonFreeberg/203c651987b124cb74e36f456a415c1d to your computer and use it in GitHub Desktop.
ManaBox to Archidekt CSV converter
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 script reads the CSV exports from the ManaBox mobile application, then writes the | |
card quantities and Scryfall ID's to a new CSV. This new CSV can then be uploaded using | |
Archidekt.com's CSV upload utility. | |
To call this script, run the following command in a terminal: | |
$ python manabox-to-archidekt.py source.csv target.csv | |
... where "source.csv" and "target.csv" are the actual names of the CSV files from ManaBox | |
and (desired) CSV file name for Archidekt. target.csv will be created by this script. | |
""" | |
import argparse | |
import csv | |
QUANTITY = 'Quantity' | |
SCRYFALLID = 'Scryfall ID' | |
def extract_columns(input_file, output_file): | |
""" | |
Reads the input CSV, creates a new CSV, writes the selected columns to the new CSV | |
""" | |
with open(input_file, 'r') as csv_file: | |
reader = csv.DictReader(csv_file) | |
fieldnames = [QUANTITY, SCRYFALLID] | |
with open(output_file, 'w', newline='') as output_csv: | |
writer = csv.DictWriter(output_csv, fieldnames=fieldnames) | |
writer.writeheader() | |
for row in reader: | |
writer.writerow({QUANTITY: row['Quantity'], SCRYFALLID: row['Scryfall ID']}) | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser() | |
parser.add_argument('input', help='Input CSV file path') | |
parser.add_argument('output', help='Output CSV file path') | |
args = parser.parse_args() | |
print("Reading from "+args.input+" and writing to "+args.output) | |
extract_columns(args.input, args.output) | |
print("Done.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment