Skip to content

Commit

Permalink
resolved suggested changes & updated code
Browse files Browse the repository at this point in the history
  • Loading branch information
MLJBrackett committed Oct 23, 2020
1 parent 8efde79 commit 8247f6a
Showing 1 changed file with 42 additions and 28 deletions.
70 changes: 42 additions & 28 deletions jsonmerge_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,47 @@
"""
import os
import argparse
import sys
import logging
#from tqdm import tqdm
from merge_files import Merge

parser = argparse.ArgumentParser(description="link-check is a broken link identifier")
parser.add_argument('-ip',
help="Input prefix",
required=True)
parser.add_argument('-op',
help="Output prefix",
required=True)
parser.add_argument('-maxFileSize',
help="The maximum file size (in bytes) that each merged file should have",
required=True)
parser.add_argument('-filepath',
help="Path to directory where all json files are stored",
required=True)
parser.add_argument('-log_level',
help="The logging level - defaults to INFO [INFO, DEBUG, ERROR]",
default="INFO")
def get_parser():
parser = argparse.ArgumentParser(
description="jsonmergeutils merges different JSON files into a single JSON object in a new file",
add_help=True)
parser.add_argument('-ip',
dest = "input_prefix",
help="Input prefix",
required=True)
parser.add_argument('-op',
dest = "output_prefix",
help="Output prefix",
required=True)
parser.add_argument('-maxFileSize',
dest = "max_file_size",
help="The maximum file size (in bytes) that each merged file should have",
type=int,
required=True
)
parser.add_argument('-dir_path',
dest ="data_dir",
help="Path to directory where all json files are stored",
required=True)
parser.add_argument('-log_level',
dest="log_level",
help="The logging level - defaults to INFO",
metavar = "{'INFO','DEBUG','ERROR'}",
choices = ['INFO', 'DEBUG', 'ERROR'],
default="INFO")
if len(sys.argv) == 1:
parser.print_help(sys.stderr)
sys.exit(1)
return parser.parse_args()


args = parser.parse_args()
logger = logging.getLogger(__name__)
def configure_logger():
def configure_logger(args):
"""
configures the logger object
"""
Expand Down Expand Up @@ -71,19 +88,16 @@ def main():
Driver Function
"""
try:
configure_logger()
data_dir = args.filepath
if not os.path.exists(data_dir):
args = get_parser()
configure_logger(args)
if not os.path.exists(args.data_dir):
raise FolderNotFoundError
input_prefix = args.ip
if not os.path.isfile('{}{}'.format(path_creator(data_dir, input_prefix), '1.json')):
if not os.path.isfile('{}{}'.format(path_creator(args.data_dir, args.input_prefix), '1.json')):
raise FileNotFoundError
output_prefix = args.op
max_file_size = int(args.maxFileSize)

merge = Merge(path_creator(data_dir, input_prefix),
path_creator(data_dir, output_prefix),
max_file_size)
merge = Merge(path_creator(args.data_dir, args.input_prefix),
path_creator(args.data_dir, args.output_prefix),
args.max_file_size)

merge.merge()

Expand Down

0 comments on commit 8247f6a

Please sign in to comment.