Skip to content

Commit 10b3ed3

Browse files
authored
Merge pull request #490 from NelsonDane/custom-pickle-path
Add support for Custom Pickle Paths
2 parents 2e12794 + 6a143ed commit 10b3ed3

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

robin_stocks/robinhood/authentication.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def respond_to_challenge(challenge_id, sms_code):
5050
return(request_post(url, payload))
5151

5252

53-
def login(username=None, password=None, expiresIn=86400, scope='internal', by_sms=True, store_session=True, mfa_code=None, pickle_name=""):
53+
def login(username=None, password=None, expiresIn=86400, scope='internal', by_sms=True, store_session=True, mfa_code=None, pickle_path="", pickle_name=""):
5454
"""This function will effectively log the user into robinhood by getting an
5555
authentication token and saving it to the session header. By default, it
5656
will store the authentication token in a pickle file and load that value
@@ -73,6 +73,8 @@ def login(username=None, password=None, expiresIn=86400, scope='internal', by_sm
7373
:type store_session: Optional[boolean]
7474
:param mfa_code: MFA token if enabled.
7575
:type mfa_code: Optional[str]
76+
:param pickle_path: Allows users to specify the path of the pickle file.
77+
Accepts both relative and absolute paths.
7678
:param pickle_name: Allows users to name Pickle token file in order to switch
7779
between different accounts without having to re-login every time.
7880
:returns: A dictionary with log in information. The 'access_token' keyword contains the access token, and the 'detail' keyword \
@@ -82,6 +84,11 @@ def login(username=None, password=None, expiresIn=86400, scope='internal', by_sm
8284
device_token = generate_device_token()
8385
home_dir = os.path.expanduser("~")
8486
data_dir = os.path.join(home_dir, ".tokens")
87+
if pickle_path:
88+
if not os.path.isabs(pickle_path):
89+
# normalize relative paths
90+
pickle_path = os.path.normpath(os.path.join(os.getcwd(), pickle_path))
91+
data_dir = pickle_path
8592
if not os.path.exists(data_dir):
8693
os.makedirs(data_dir)
8794
creds_file = "robinhood" + pickle_name + ".pickle"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
long_description = f.read()
88

99
setup(name='robin_stocks',
10-
version='3.1.2',
10+
version='3.1.3',
1111
description='A Python wrapper around the Robinhood API',
1212
long_description=long_description,
1313
long_description_content_type='text/x-rst',

0 commit comments

Comments
 (0)