From 7e1c70c32e78467cdcbd85a10521589cea6940f7 Mon Sep 17 00:00:00 2001 From: Millan Kumar Date: Fri, 4 Apr 2025 18:48:43 -0400 Subject: [PATCH 1/2] Using argparse so you can tab complete files --- processor.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/processor.py b/processor.py index deef9cb..dc0a1fc 100644 --- a/processor.py +++ b/processor.py @@ -2,6 +2,7 @@ import plotly.express as px import os import shutil +import argparse def process_file(file_path): df = pd.read_csv(file_path, header=None) @@ -65,10 +66,14 @@ def process_file(file_path): print(f"Summary saved to {output_dir}/battery_summary.csv") print(f"Interactive plot saved as {output_dir}/cell_voltages_plot.html") -# Prompt user for the folder containing CSV files -folder_path = input("Enter the folder path containing CSV files: ") +def main(): + parser = argparse.ArgumentParser(description="Process battery CSV files.") + parser.add_argument("folder", help="Folder containing CSV files") + args = parser.parse_args() + + for file in os.listdir(args.folder): + if file.endswith(".csv"): + process_file(os.path.join(args.folder, file)) -# Process all CSV files in the specified directory -for file in os.listdir(folder_path): - if file.endswith(".csv"): - process_file(os.path.join(folder_path, file)) +if __name__ == "__main__": + main() From cd20d2d759247b7039453fad9f7183c302426ae3 Mon Sep 17 00:00:00 2001 From: Millan Kumar Date: Fri, 4 Apr 2025 18:50:00 -0400 Subject: [PATCH 2/2] Can give it a single file or a folder --- processor.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/processor.py b/processor.py index dc0a1fc..8a91e22 100644 --- a/processor.py +++ b/processor.py @@ -68,12 +68,17 @@ def process_file(file_path): def main(): parser = argparse.ArgumentParser(description="Process battery CSV files.") - parser.add_argument("folder", help="Folder containing CSV files") + parser.add_argument("path", help="Path to a single CSV file or a folder containing CSV files.") args = parser.parse_args() - for file in os.listdir(args.folder): - if file.endswith(".csv"): - process_file(os.path.join(args.folder, file)) + if os.path.isfile(args.path): + process_file(args.path) + elif os.path.isdir(args.path): + for file in os.listdir(args.path): + if file.endswith(".csv"): + process_file(os.path.join(args.path, file)) + else: + print(f"Error: {args.path} is not a valid file or directory.") if __name__ == "__main__": main()