Skip to content

Commit

Permalink
Merge pull request #490 from NelsonDane/custom-pickle-path
Browse files Browse the repository at this point in the history
Add support for Custom Pickle Paths
  • Loading branch information
jmfernandes authored Oct 12, 2024
2 parents 2e12794 + 6a143ed commit 10b3ed3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion robin_stocks/robinhood/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def respond_to_challenge(challenge_id, sms_code):
return(request_post(url, payload))


def login(username=None, password=None, expiresIn=86400, scope='internal', by_sms=True, store_session=True, mfa_code=None, pickle_name=""):
def login(username=None, password=None, expiresIn=86400, scope='internal', by_sms=True, store_session=True, mfa_code=None, pickle_path="", pickle_name=""):
"""This function will effectively log the user into robinhood by getting an
authentication token and saving it to the session header. By default, it
will store the authentication token in a pickle file and load that value
Expand All @@ -73,6 +73,8 @@ def login(username=None, password=None, expiresIn=86400, scope='internal', by_sm
:type store_session: Optional[boolean]
:param mfa_code: MFA token if enabled.
:type mfa_code: Optional[str]
:param pickle_path: Allows users to specify the path of the pickle file.
Accepts both relative and absolute paths.
:param pickle_name: Allows users to name Pickle token file in order to switch
between different accounts without having to re-login every time.
:returns: A dictionary with log in information. The 'access_token' keyword contains the access token, and the 'detail' keyword \
Expand All @@ -82,6 +84,11 @@ def login(username=None, password=None, expiresIn=86400, scope='internal', by_sm
device_token = generate_device_token()
home_dir = os.path.expanduser("~")
data_dir = os.path.join(home_dir, ".tokens")
if pickle_path:
if not os.path.isabs(pickle_path):
# normalize relative paths
pickle_path = os.path.normpath(os.path.join(os.getcwd(), pickle_path))
data_dir = pickle_path
if not os.path.exists(data_dir):
os.makedirs(data_dir)
creds_file = "robinhood" + pickle_name + ".pickle"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
long_description = f.read()

setup(name='robin_stocks',
version='3.1.2',
version='3.1.3',
description='A Python wrapper around the Robinhood API',
long_description=long_description,
long_description_content_type='text/x-rst',
Expand Down

0 comments on commit 10b3ed3

Please sign in to comment.