From 930c12d33e1093f874a4beb4d6376621e464e8c0 Mon Sep 17 00:00:00 2001 From: Terry Truong Date: Sat, 20 Aug 2022 13:16:21 +1000 Subject: Use argparse in python scripts --- backend/tolData/genImgs.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'backend/tolData/genImgs.py') diff --git a/backend/tolData/genImgs.py b/backend/tolData/genImgs.py index ecca8e0..930990b 100755 --- a/backend/tolData/genImgs.py +++ b/backend/tolData/genImgs.py @@ -4,9 +4,8 @@ import sys, os, subprocess import sqlite3, urllib.parse import signal -usageInfo = f""" -Usage: {sys.argv[0]} - +import argparse +parser = argparse.ArgumentParser(description=""" Reads node IDs and image paths from a file, and possibly from a directory, and generates cropped/resized versions of those images into a directory, with names of the form 'nodeId1.jpg'. Also adds image metadata to the @@ -15,10 +14,8 @@ database. SIGINT can be used to stop, and the program can be re-run to continue processing. It uses already-existing database entries to decide what to skip. -""" -if len(sys.argv) > 1: - print(usageInfo, file=sys.stderr) - sys.exit(1) +""", formatter_class=argparse.RawDescriptionHelpFormatter) +parser.parse_args() imgListFile = "imgList.txt" outDir = "img/" -- cgit v1.2.3