Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[paypal] Update parsing because Paypal changed website. #70

Merged
merged 1 commit into from
Apr 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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