From 289bad05cb7d908d4cc32430399623954e1719c9 Mon Sep 17 00:00:00 2001 From: Pierros Papadeas Date: Fri, 10 May 2019 10:20:47 +0300 Subject: [PATCH] Decoupled credentials from argparse into configuration file Signed-off-by: Pierros Papadeas --- .gitignore | 1 + README.md | 7 ++++++- env-dist | 5 +++++ requirements.txt | 1 + schedule_single_station.py | 9 ++------- settings.py | 15 +++++++++++---- setup.cfg | 35 +++++++++++++++++++++++++++++++++++ 7 files changed, 61 insertions(+), 12 deletions(-) create mode 100644 env-dist create mode 100644 setup.cfg diff --git a/.gitignore b/.gitignore index 749ccda..bd6cc8c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ __pycache__/ *.py[cod] *$py.class +.env diff --git a/README.md b/README.md index c65b434..7d01d94 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,11 @@ SatNOGS network. It uses code from the SatNOGS network scheduler. It requires pip install -r requirements.txt ``` +## Configuration + +Copy the env-dist file to .env and set your legacy SatNOGS Network credentials. + + ## Usage The following command will list all available command-line arguments: @@ -19,4 +24,4 @@ The following command will list all available command-line arguments: ## License [![license](https://img.shields.io/badge/license-AGPL%203.0-6672D8.svg)](LICENSE) -Copyright 2018 - Cees Bassa, Fabian Schmidt, Pierros Papadeas +Copyright 2019 - Cees Bassa, Fabian Schmidt, Pierros Papadeas diff --git a/env-dist b/env-dist new file mode 100644 index 0000000..1cc532e --- /dev/null +++ b/env-dist @@ -0,0 +1,5 @@ +# Copy this file to .env and complete the information needed + +# Username and password to SatNOGS Network using the old authentication system +NETWORK_USERNAME = '' +NETWORK_PASSWORD = '' diff --git a/requirements.txt b/requirements.txt index 8a8ac80..e5265ef 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,4 @@ satellitetle>=0.5.0 requests lxml tqdm +python-decouple diff --git a/schedule_single_station.py b/schedule_single_station.py index 76b5d80..c3066b8 100755 --- a/schedule_single_station.py +++ b/schedule_single_station.py @@ -90,9 +90,6 @@ def main(): parser.add_argument("-w", "--wait", help="Wait time between consecutive observations (for setup and slewing)" + " [seconds; default: 0.0]", type=float, default=0) - parser.add_argument("-u", "--username", - help="old SatNOGS Network username (NOT the new Auth0 username)") - parser.add_argument("-p", "--password", help="old SatNOGS Network password") parser.add_argument("-n", "--dryrun", help="Dry run (do not schedule passes)", action="store_true") parser.add_argument("-P", "--priorities", help="File with transmitter priorities. Should have" + @@ -124,8 +121,6 @@ def main(): if wait_time_seconds < 0: wait_time_seconds = 0.0 cache_dir = "/tmp/cache" - username = args.username - password = args.password schedule = not args.dryrun search_transmitters = args.search_transmitters priority_filename = args.priorities @@ -328,8 +323,8 @@ def main(): login_hidden_inputs = login_html.xpath( r'//form//input[@type="hidden"]') # Get CSFR token form = {x.attrib["name"]: x.attrib["value"] for x in login_hidden_inputs} - form["login"] = username - form["password"] = password + form["login"] = settings.NETWORK_USERNAME + form["password"] = settings.NETWORK_PASSWORD # Login result = session.post(loginUrl, diff --git a/settings.py b/settings.py index 726790b..d1e4786 100644 --- a/settings.py +++ b/settings.py @@ -1,4 +1,11 @@ -DB_BASE_URL = 'https://db.satnogs.org' -NETWORK_BASE_URL = 'https://network.satnogs.org' -CACHE_AGE = 24 -MAX_NORAD_CAT_ID = 90000 +from decouple import config + +# Basic settings +DB_BASE_URL = config('DB_BASE_URL', default='https://db.satnogs.org') +NETWORK_BASE_URL = config('NETWORK_BASE_URL', default='https://network.satnogs.org') +CACHE_AGE = config('CACHE_AGE', default=24) +MAX_NORAD_CAT_ID = config('CACHE_AGE', default=90000) + +# Credentials +NETWORK_USERNAME = config('NETWORK_USERNAME', default='') +NETWORK_PASSWORD = config('NETWORK_PASSWORD', default='') diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..56f6299 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,35 @@ +[metadata] +name = satnogs-auto-scheduler +url = https://gitlab.com/librespacefoundation/satnogs/satnogs-auto-scheduler +author = SatNOGS project +author_email = dev@satnogs.org +license = AGPLv3 +classifiers = + Development Status :: 4 - Beta + Environment :: Console + Intended Audience :: Telecommunications Industry + Intended Audience :: Science/Research + License :: OSI Approved :: GNU Affero General Public License v3 + Operating System :: POSIX :: Linux + Programming Language :: Python + Programming Language :: Python :: 3.7 + Topic :: Communications :: Ham Radio +description = SatNOGS Auto Scheduler + +[options] +packages = find: +include_package_data = True +install_requires = + # Basic + requests + lxml + tqdm + python-decouple + # Astronomy + satellitetle~=0.6.0 + ephem + +[flake8] +max-complexity = 25 +max-line-length = 100 +ignore = F403,W504