From 36d9abf210e73c4bba06b25a1f26aa726f4a0ea6 Mon Sep 17 00:00:00 2001 From: Scott Rowe Date: Thu, 7 Feb 2019 11:22:29 -0500 Subject: [PATCH] change the way the api key path is generated (#131) * change the way the api key path is generated * remove eroneous catch block --- quandl/api_config.py | 29 +++++++++++++---------------- quandl/version.py | 2 +- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/quandl/api_config.py b/quandl/api_config.py index 986504e..6464e6b 100644 --- a/quandl/api_config.py +++ b/quandl/api_config.py @@ -1,3 +1,6 @@ +import os + + class ApiConfig: api_key = None api_protocol = 'https://' @@ -14,8 +17,7 @@ class ApiConfig: def save_key(apikey, filename=None): if filename is None: - import pathlib - filename = str(pathlib.Path.home()) + "/.quandl_apikey" + filename = os.path.join(os.path.expanduser('~'), '.quandl_apikey') fileptr = open(filename, 'w') fileptr.write(apikey) @@ -25,17 +27,12 @@ def save_key(apikey, filename=None): def read_key(filename=None): if filename is None: - import pathlib - filename = str(pathlib.Path.home()) + "/.quandl_apikey" - - try: - fileptr = open(filename, 'r') - apikey = fileptr.read() - fileptr.close() - - if apikey: - ApiConfig.api_key = apikey - else: - raise Exception("File '{:s}' is empty.".format(filename)) - except ValueError: - raise Exception("File '{:s}' not found.".format(filename)) + filename = os.path.join(os.path.expanduser('~'), '.quandl_apikey') + + with open(filename, 'r') as f: + apikey = f.read() + + if not apikey: + raise ValueError("File '{:s}' is empty.".format(filename)) + + ApiConfig.api_key = apikey diff --git a/quandl/version.py b/quandl/version.py index 9254ef5..2cf3118 100644 --- a/quandl/version.py +++ b/quandl/version.py @@ -1 +1 @@ -VERSION = '3.4.5' +VERSION = '3.4.6'