#NEWLINE# def Authorize( self , email , password ) : #NEWLINE# #INDENT# from tapiriik.auth.credential_storage import CredentialStore #NEWLINE# soap_auth_data = { #NEWLINE# #INDENT# 'username' : email , #NEWLINE# 'password' : password , #NEWLINE# #UNINDENT# } #NEWLINE# resp = requests . post ( 'https://www.trainingpeaks.com/tpwebservices/service.asmx/AuthenticateAccount' , data = soap_auth_data ) #NEWLINE# if ( resp . status_code != 200 ) : #NEWLINE# #INDENT# raise APIException ( 'Invalid login' ) #NEWLINE# #UNINDENT# soap_auth_data . update ( { #NEWLINE# #INDENT# 'types' : 'CoachedPremium,SelfCoachedPremium,SharedCoachedPremium,CoachedFree,SharedFree,Plan' , #NEWLINE# #UNINDENT# } ) #NEWLINE# users_resp = requests . post ( 'https://www.trainingpeaks.com/tpwebservices/service.asmx/GetAccessibleAthletes' , data = soap_auth_data ) #NEWLINE# users_resp = etree . XML ( users_resp . content ) #NEWLINE# personId = None #NEWLINE# for xperson in users_resp : #NEWLINE# #INDENT# xpersonid = xperson . find ( 'tpw:PersonId' , namespaces = self . _tp_ns ) #NEWLINE# if ( ( xpersonid is not None ) and xpersonid . text ) : #NEWLINE# #INDENT# personId = int ( xpersonid . text ) #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# if ( not personId ) : #NEWLINE# #INDENT# raise APIException ( 'Account not premium' , block = True , user_exception = UserException ( UserExceptionType . AccountUnpaid , intervention_required = True , extra = personId ) ) #NEWLINE# #UNINDENT# return ( personId , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'Username' : CredentialStore . Encrypt ( email ) , #NEWLINE# 'Password' : CredentialStore . Encrypt ( password ) , #NEWLINE# #UNINDENT# } )