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/genEolNameData.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'backend/tolData/genEolNameData.py') diff --git a/backend/tolData/genEolNameData.py b/backend/tolData/genEolNameData.py index 1b19a47..2c5414b 100755 --- a/backend/tolData/genEolNameData.py +++ b/backend/tolData/genEolNameData.py @@ -3,24 +3,21 @@ import sys, re, os import html, csv, sqlite3 -usageInfo = f""" -Usage: {sys.argv[0]} - +import argparse +parser = argparse.ArgumentParser(description=""" Reads files describing name data from the 'Encyclopedia of Life' site, tries to associate names with nodes in the tree-of-life database, and adds tables to represent associated names. Reads a vernacularNames.csv file: - Starts with a header line containing: - page_id, canonical_form, vernacular_string, language_code, - resource_name, is_preferred_by_resource, is_preferred_by_eol - The canonical_form and vernacular_string fields contain names - associated with the page ID. Names are not always unique to - particular page IDs. -""" -if len(sys.argv) > 1: - print(usageInfo, file=sys.stderr) - sys.exit(1) + Starts with a header line containing: + page_id, canonical_form, vernacular_string, language_code, + resource_name, is_preferred_by_resource, is_preferred_by_eol + The canonical_form and vernacular_string fields contain names + associated with the page ID. Names are not always unique to + particular page IDs. +""", formatter_class=argparse.RawDescriptionHelpFormatter) +parser.parse_args() vnamesFile = "eol/vernacularNames.csv" # Had about 2.8e6 entries dbFile = "data.db" -- cgit v1.2.3