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/lookupPage.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'backend/tolData/enwiki/lookupPage.py') diff --git a/backend/tolData/enwiki/lookupPage.py b/backend/tolData/enwiki/lookupPage.py index 1a90851..e7b95f0 100755 --- a/backend/tolData/enwiki/lookupPage.py +++ b/backend/tolData/enwiki/lookupPage.py @@ -4,19 +4,17 @@ import sys, re import bz2 import sqlite3 -usageInfo = f""" -Usage: {sys.argv[0]} title1 - -Looks up a page with title title1 in the wiki dump, using -the dump-index db, and prints the corresponding . -""" -if len(sys.argv) != 2: - print(usageInfo, file=sys.stderr) - sys.exit(1) +import argparse +parser = argparse.ArgumentParser(description=""" +Looks up a page with title title1 in the wiki dump, using the dump-index +db, and prints the corresponding . +""", formatter_class=argparse.RawDescriptionHelpFormatter) +parser.add_argument("title", help="The title to look up") +args = parser.parse_args() dumpFile = "enwiki-20220501-pages-articles-multistream.xml.bz2" indexDb = "dumpIndex.db" -pageTitle = sys.argv[1].replace("_", " ") +pageTitle = args.title.replace("_", " ") print("Looking up offset in index db") dbCon = sqlite3.connect(indexDb) -- cgit v1.2.3