diff options
| author | Terry Truong <terry06890@gmail.com> | 2022-08-20 13:16:21 +1000 |
|---|---|---|
| committer | Terry Truong <terry06890@gmail.com> | 2022-08-20 13:16:21 +1000 |
| commit | 930c12d33e1093f874a4beb4d6376621e464e8c0 (patch) | |
| tree | 381722fc3ab9ebda482cb18d29e1091458aa93da /backend/tolData/enwiki/lookupPage.py | |
| parent | 8144003565797f0d18645a416b95d4365bba5fdd (diff) | |
Use argparse in python scripts
Diffstat (limited to 'backend/tolData/enwiki/lookupPage.py')
| -rwxr-xr-x | backend/tolData/enwiki/lookupPage.py | 18 |
1 files changed, 8 insertions, 10 deletions
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 <page>. -""" -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 <page>. +""", 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) |
