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

Commit 36d9abf

Browse files
authored
change the way the api key path is generated (#131)
* change the way the api key path is generated * remove eroneous catch block
1 parent 72306cb commit 36d9abf

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

quandl/api_config.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import os
2+
3+
14
class ApiConfig:
25
api_key = None
36
api_protocol = 'https://'
@@ -14,8 +17,7 @@ class ApiConfig:
1417

1518
def save_key(apikey, filename=None):
1619
if filename is None:
17-
import pathlib
18-
filename = str(pathlib.Path.home()) + "/.quandl_apikey"
20+
filename = os.path.join(os.path.expanduser('~'), '.quandl_apikey')
1921

2022
fileptr = open(filename, 'w')
2123
fileptr.write(apikey)
@@ -25,17 +27,12 @@ def save_key(apikey, filename=None):
2527

2628
def read_key(filename=None):
2729
if filename is None:
28-
import pathlib
29-
filename = str(pathlib.Path.home()) + "/.quandl_apikey"
30-
31-
try:
32-
fileptr = open(filename, 'r')
33-
apikey = fileptr.read()
34-
fileptr.close()
35-
36-
if apikey:
37-
ApiConfig.api_key = apikey
38-
else:
39-
raise Exception("File '{:s}' is empty.".format(filename))
40-
except ValueError:
41-
raise Exception("File '{:s}' not found.".format(filename))
30+
filename = os.path.join(os.path.expanduser('~'), '.quandl_apikey')
31+
32+
with open(filename, 'r') as f:
33+
apikey = f.read()
34+
35+
if not apikey:
36+
raise ValueError("File '{:s}' is empty.".format(filename))
37+
38+
ApiConfig.api_key = apikey

quandl/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = '3.4.5'
1+
VERSION = '3.4.6'

0 commit comments

Comments
 (0)