From ea4bbea4c02b09924c03254cee0e3bd73dc7bfed Mon Sep 17 00:00:00 2001 From: Martin <@martinoneutrino> Date: Sat, 20 Feb 2021 13:02:48 -0700 Subject: [PATCH] Add auth_token argument to allow passing existing JWT OAuth2 token --- Robinhood.py | 5 +++++ csv-export.py | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Robinhood.py b/Robinhood.py index 9138883..88c5ee9 100644 --- a/Robinhood.py +++ b/Robinhood.py @@ -101,6 +101,11 @@ def login(self, username, password, device_token ,mfa_code=None): self.headers['Authorization'] = 'Bearer ' + self.auth_token return True + def use_token(self, access_token): + self.auth_token = access_token + self.headers['Authorization'] = 'Bearer ' + self.auth_token + return True + ############################## #GET DATA ############################## diff --git a/csv-export.py b/csv-export.py index 64526f7..2db5c56 100644 --- a/csv-export.py +++ b/csv-export.py @@ -23,6 +23,8 @@ '--mfa_code', help='your Robinhood mfa_code') parser.add_argument( '--device_token', help='your device token') +parser.add_argument( + '--auth_token', help='your oauth2 token') parser.add_argument( '--profit', action='store_true', help='calculate profit for each sale') parser.add_argument( @@ -32,13 +34,18 @@ password = args.password mfa_code = args.mfa_code device_token = args.device_token +auth_token = args.auth_token load_dotenv(find_dotenv()) robinhood = Robinhood() # login to Robinhood -logged_in = collect_login_data(robinhood_obj=robinhood, username=username, password=password, device_token=device_token, mfa_code=mfa_code) +if args.auth_token: + robinhood.use_token(args.auth_token) + logged_in = True +else: + logged_in = collect_login_data(robinhood_obj=robinhood, username=username, password=password, device_token=device_token, mfa_code=mfa_code) print("Pulling trades. Please wait...")