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/tilo.py | |
| parent | 8144003565797f0d18645a416b95d4365bba5fdd (diff) | |
Use argparse in python scripts
Diffstat (limited to 'backend/tilo.py')
| -rwxr-xr-x | backend/tilo.py | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/backend/tilo.py b/backend/tilo.py index 8bbe528..d86e94c 100755 --- a/backend/tilo.py +++ b/backend/tilo.py @@ -5,14 +5,7 @@ import urllib.parse import sqlite3 import gzip, jsonpickle -dbFile = "tolData/data.db" -DEFAULT_SUGG_LIM = 5 -MAX_SUGG_LIM = 50 -ROOT_NAME = "cellular organisms" - -usageInfo = f""" -Usage: {sys.argv[0]} - +HELP_INFO = """ WSGI script that serves tree-of-life data, in JSON form. Expected HTTP query parameters: @@ -30,9 +23,15 @@ Expected HTTP query parameters: weakly-trimmed, images-only, and picked-nodes trees. The default is 'images'. """ -if len(sys.argv) > 1: - print(usageInfo, file=sys.stderr) - sys.exit(1) +if __name__ == '__main__': + import argparse + parser = argparse.ArgumentParser(description=HELP_INFO, formatter_class=argparse.RawDescriptionHelpFormatter) + parser.parse_args() + +DB_FILE = "tolData/data.db" +DEFAULT_SUGG_LIM = 5 +MAX_SUGG_LIM = 50 +ROOT_NAME = "cellular organisms" # Classes for objects sent as responses (matches lib.ts types in client-side code) class TolNode: @@ -316,9 +315,8 @@ def handleReq(dbCur, environ): return None # Entry point for the WSGI script def application(environ, start_response): - global dbFile # Open db - dbCon = sqlite3.connect(dbFile) + dbCon = sqlite3.connect(DB_FILE) dbCur = dbCon.cursor() # Get response object val = handleReq(dbCur, environ) |
