refactor argument parsing from sys to argparse

This commit is contained in:
ferricles 2022-06-25 16:35:09 -07:00
parent b175bdbcc7
commit ab0934b77d
5 changed files with 33 additions and 10 deletions

View file

@ -7,8 +7,13 @@ Usage: python clean_json.py [infile rel path] [outfile rel path]
'''
if __name__ == "__main__":
import sys
import json
infile = sys.argv[1]
outfile = sys.argv[2]
import argparse
parser = argparse.ArgumentParser(description="Pull data from wynn API.")
parser.add_argument('infile', help='input file to read data from')
parser.add_argument('outfile', help='output file to dump clean data into')
args = parser.parse_args()
infile, outfile = args.infile, args.outfile
json.dump(json.load(open(infile)), open(outfile, "w"), indent = 2)

View file

@ -6,8 +6,13 @@ Usage: python compress_json.py [infile rel path] [outfile rel path]
'''
if __name__ == "__main__":
import sys
import json
infile = sys.argv[1]
outfile = sys.argv[2]
import argparse
parser = argparse.ArgumentParser(description="Pull data from wynn API.")
parser.add_argument('infile', help='input file to read data from')
parser.add_argument('outfile', help='output file to dump clean data into')
args = parser.parse_args()
infile, outfile = args.infile, args.outfile
json.dump(json.load(open(infile)), open(outfile, "w"))

View file

@ -13,7 +13,11 @@ import os
import base64
import argparse
infile, outfile = sys.argv[1], sys.argv[2] if len(sys.argv) > 2 else sys.argv[1]
parser = argparse.ArgumentParser(description="Process raw pulled ingredient data.")
parser.add_argument('infile', help='input file to read data from')
parser.add_argument('outfile', help='output file to dump clean data into')
args = parser.parse_args()
infile, outfile = args.infile, args.outfile
with open(infile, "r") as in_file:
ing_data = json.loads(in_file.read())

View file

@ -14,8 +14,13 @@ import json
import sys
import os
import base64
import argparse
infile, outfile = sys.argv[1], sys.argv[2] if len(sys.argv) > 2 else sys.argv[1]
parser = argparse.ArgumentParser(description="Process raw pulled item data.")
parser.add_argument('infile', help='input file to read data from')
parser.add_argument('outfile', help='output file to dump clean data into')
args = parser.parse_args()
infile, outfile = args.infile, args.outfile
with open(infile, "r") as in_file:
data = json.loads(in_file.read())

View file

@ -11,9 +11,13 @@ import json
import sys
import os
import base64
import argparse
infile, outfile = sys.argv[1], sys.argv[2] if len(sys.argv) > 2 else sys.argv[1]
parser = argparse.ArgumentParser(description="Process raw pulled recipe data.")
parser.add_argument('infile', help='input file to read data from')
parser.add_argument('outfile', help='output file to dump clean data into')
args = parser.parse_args()
infile, outfile = args.infile, args.outfile
with open(infile, "r") as in_file:
recipe_data = json.loads(in_file.read())