Skip to content
This repository has been archived by the owner on Apr 30, 2022. It is now read-only.

Commit

Permalink
change the way the api key path is generated (#131)
Browse files Browse the repository at this point in the history
* change the way the api key path is generated

* remove eroneous catch block
  • Loading branch information
A-Scott-Rowe authored Feb 7, 2019
1 parent 72306cb commit 36d9abf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
29 changes: 13 additions & 16 deletions quandl/api_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import os


class ApiConfig:
api_key = None
api_protocol = 'https://'
Expand All @@ -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)
Expand All @@ -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
2 changes: 1 addition & 1 deletion quandl/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = '3.4.5'
VERSION = '3.4.6'

0 comments on commit 36d9abf

Please sign in to comment.