From 4a9a16e792f824eeeef85b394fd28274f6c33152 Mon Sep 17 00:00:00 2001 From: mattmcw Date: Wed, 3 Jul 2024 19:40:24 -0400 Subject: [PATCH] Add argparse to assign different host and port via command line --- app.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index 7df2740..87ae7ed 100755 --- a/app.py +++ b/app.py @@ -10,7 +10,16 @@ from bottle import ( import thesethreewords as these import sys +from argparse import ArgumentParser +parser = ArgumentParser( + prog='these-3-words-api', + description='Hosts an API for these-3-words API', + epilog='Defaults to: 0.0.0.0:8080') +parser.add_argument('--host', default='0.0.0.0', + help='Host to bind to (default: 0.0.0.0)') +parser.add_argument('--port', type=int, default=8080, help='Port to bind to (default: 8080)') +args = parser.parse_args() example_locs = [("sydney", (-33.867480754852295, 151.20700120925903)), ("battery", (40.70329427719116, -74.0170168876648)), @@ -90,6 +99,6 @@ def hashToLatLng(threewords): if __name__ == '__main__': - run(host='0.0.0.0', port=8080) + run(host=args.host, port=args.port) app = bottle.default_app()