From f2b1bb8d2a040c4f56cb7468e7cc1daf14c935ad Mon Sep 17 00:00:00 2001 From: moshferatu Date: Wed, 13 Dec 2023 08:58:35 -0800 Subject: [PATCH] Switch to using dotenv module to retrieve environment variables --- .gitignore | 1 + download_spx_quotes.py | 13 +++++++++---- requirements.txt | 1 + 3 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2eea525 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/download_spx_quotes.py b/download_spx_quotes.py index d6ebc92..f88b690 100644 --- a/download_spx_quotes.py +++ b/download_spx_quotes.py @@ -5,7 +5,12 @@ import schedule import time import zipfile -quotes_directory = os.environ['DOWNLOAD_DIRECTORY'] +from dotenv import load_dotenv +from os import getenv + +load_dotenv() + +quotes_directory = getenv('DOWNLOAD_DIRECTORY') download_directory = quotes_directory + 'Zip Archive/' def process_file(file: str): @@ -20,11 +25,11 @@ def download_quotes(): client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.connect( hostname='sftp.datashop.livevol.com', - username=os.environ['USER'], - password=os.environ['PASSWORD'] + username=getenv('USER'), + password=getenv('PASSWORD') ) sftp = client.open_sftp() - sftp.chdir('./subscriptions/' + os.environ['ORDER'] + '/' + os.environ['ITEM']) + sftp.chdir('./subscriptions/' + getenv('ORDER') + '/' + getenv('ITEM')) files = sftp.listdir() for file in files: local_file = download_directory + file diff --git a/requirements.txt b/requirements.txt index 64f7c4b..b71f29f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ pandas paramiko +python-dotenv pytz schedule \ No newline at end of file