Skip to content

Commit

Permalink
[paypal] Update parsing because Paypal changed website. (#70)
Browse files Browse the repository at this point in the history
* another attribute parsed for CSRF token
* transactions list and transactions detail schemas needed minor updates
  • Loading branch information
Zburatorul authored Apr 11, 2022
1 parent aa3b4ba commit 9cc278c
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions finance_dl/paypal.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,30 @@
'properties': {
'data': {
'type': 'object',
'required': ['activity'],
'required': ['data'],
'properties': {
'activity': {
'data': {
'type': 'object',
'required': ['transactions'],
'required': ['activity'],
'properties': {
'transactions': {
'type': 'array',
'items': {
'type': 'object',
'required': ['id'],
'properties': {
'id': {
'type': 'string',
'pattern': r'^[A-Za-z0-9\-]+$',
},
'activity': {
'type': 'object',
'required': ['transactions'],
'properties': {
'transactions': {
'type': 'array',
'items': {
'type': 'object',
'required': ['id'],
'properties': {
'id': {
'type': 'string',
'pattern': r'^[A-Za-z0-9\-]+$',
},
},
}
},
}
},
},
},
},
Expand All @@ -102,9 +108,9 @@
'properties': {
'data': {
'type': 'object',
'required': ['details'],
'required': ['amount'],
'properties': {
'details': {
'amount': {
'type': 'object',
},
},
Expand Down Expand Up @@ -168,9 +174,9 @@ def get_csrf_token(self):
logging.info('Getting CSRF token')
self.driver.get('https://www.paypal.com/myaccount/transactions/')
# Get CSRF token
body_element, = self.wait_and_locate((By.XPATH,
'//body[@data-token!=""]'))
self.csrf_token = body_element.get_attribute('data-token')
body_element, = self.wait_and_locate((By.ID, "__react_data__"))
attribute_object = json.loads(body_element.get_attribute("data"))
self.csrf_token = attribute_object["_csrf"]
return self.csrf_token

def get_transaction_list(self):
Expand All @@ -188,7 +194,7 @@ def get_transaction_list(self):
resp.raise_for_status()
j = resp.json()
jsonschema.validate(j, transaction_list_schema)
return j['data']['activity']['transactions']
return j['data']['data']['activity']['transactions']

def save_transactions(self):
transaction_list = self.get_transaction_list()
Expand Down Expand Up @@ -243,7 +249,7 @@ def save_transactions(self):
jsonschema.validate(j, transaction_details_schema)
with atomic_write(json_path, mode='wb', overwrite=True) as f:
f.write(
json.dumps(j['data']['details'], indent=' ').encode())
json.dumps(j['data'], indent=' ', sort_keys=True).encode())

def run(self):
if not os.path.exists(self.output_directory):
Expand Down

0 comments on commit 9cc278c

Please sign in to comment.