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/enwiki/downloadImgLicenseInfo.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'backend/tolData/enwiki/downloadImgLicenseInfo.py') diff --git a/backend/tolData/enwiki/downloadImgLicenseInfo.py b/backend/tolData/enwiki/downloadImgLicenseInfo.py index 399922e..dd39d54 100755 --- a/backend/tolData/enwiki/downloadImgLicenseInfo.py +++ b/backend/tolData/enwiki/downloadImgLicenseInfo.py @@ -5,19 +5,16 @@ import sqlite3, urllib.parse, html import requests import time, signal -usageInfo = f""" -Usage: {sys.argv[0]} - +import argparse +parser = argparse.ArgumentParser(description=""" Reads image names from a database, and uses enwiki's online API to obtain licensing information for them, adding the info to the database. SIGINT causes the program to finish an ongoing download and exit. The program can be re-run to continue downloading, and looks at already-processed names 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() imgDb = "imgData.db" apiUrl = "https://en.wikipedia.org/w/api.php" -- cgit v1.2.3