@@ -50,7 +50,7 @@ def respond_to_challenge(challenge_id, sms_code):
50
50
return (request_post (url , payload ))
51
51
52
52
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 = "" ):
54
54
"""This function will effectively log the user into robinhood by getting an
55
55
authentication token and saving it to the session header. By default, it
56
56
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
73
73
:type store_session: Optional[boolean]
74
74
:param mfa_code: MFA token if enabled.
75
75
: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.
76
78
:param pickle_name: Allows users to name Pickle token file in order to switch
77
79
between different accounts without having to re-login every time.
78
80
: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
82
84
device_token = generate_device_token ()
83
85
home_dir = os .path .expanduser ("~" )
84
86
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
85
92
if not os .path .exists (data_dir ):
86
93
os .makedirs (data_dir )
87
94
creds_file = "robinhood" + pickle_name + ".pickle"
0 commit comments