diff --git a/src/arguments.py b/src/arguments.py index db1e133c..281d9678 100644 --- a/src/arguments.py +++ b/src/arguments.py @@ -38,6 +38,12 @@ def parse(args): help="Whether to get only passed build reports", ) + parser.add_argument( + "--record", + required=False, + type=str, + help="Record the analysis to a separate file", + ) # parse the arguments and return the finished result arguments_finished = parser.parse_args(args) return arguments_finished diff --git a/textmining.py b/textmining.py index d4b5d6c3..69ea8568 100644 --- a/textmining.py +++ b/textmining.py @@ -1,15 +1,42 @@ """CLI Entry point""" +import json import sys +import os + +import src.analyzer as az +import src.summarizer as sz +import src.arguments as arg -from src import analyzer as az -from src import summarizer as sz -from src import arguments if __name__ == "__main__": - tm_arguments = arguments.parse(sys.argv[1:]) + + # Making a new directory to store the files. + directory = "records" + path = os.path.join(directory) + try: + os.mkdir(path) + except OSError as error: + print(error) + + tm_arguments = arg.parse(sys.argv[1:]) directory = tm_arguments.directory function = tm_arguments.function - if function == "frequency": - print(az.dir_frequency(directory)) - elif function == "summary": - print(sz.summarizer(directory)) + record = tm_arguments.record + if function == "summary": + # Determine if user wants to keep a record of the result. + if record: + # Write the summary into a json file. + data = sz.summarizer(directory) + file = open(path + "/" + record + ".json", "w") + json.dump(data, file, indent=4) + file.close() + else: + print(sz.summarizer(directory)) + elif function == "frequency": + if record: + data = az.dir_frequency(directory) + file = open(path + "/" + record + ".json", "w") + json.dump(data, file, indent=4) + file.close() + else: + print(az.dir_frequency(directory))