Last active
November 6, 2024 08:18
-
-
Save knoxxs/d69768b1262562439775b2801511b884 to your computer and use it in GitHub Desktop.
Use this code to export Amazon pay transactions (https://www.amazon.in/pay/history?tab=ALL&filter={"dateRanges":[{"from":"2020-01-29","to":"2021-01-31"}]}) to csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// item = document.querySelectorAll("#transactions-section-desktop #transaction-desktop")[7] | |
csv = '"' + ['Date','Deposit','Withdrawl','Description'].join('","') + '"\n', count = 0; | |
document.querySelectorAll("#transactions-section-desktop #transaction-desktop").forEach(function (item) { | |
console.log('#' + ++count + '\n' + item.innerText); | |
leftItems = item.querySelectorAll("a.a-expander-header .a-row .a-text-left"); | |
if (leftItems.length != 1) { | |
throw 'leftItems is not equal to 1.\n' + item.innerText; | |
} | |
leftItem = leftItems[0]; | |
dateTime = leftItem.children[2].innerText.replaceAll(/,.+/g, '').replaceAll('Expected Credit on: ','').replaceAll('Credited on: ',''); | |
description = leftItem.children[0].innerText.trim() + ' using ' + leftItem.children[1].innerText.trim(); | |
description = description.replaceAll(/\s{2,}/g, ' ').replaceAll(/\n+/g, ' - '); | |
rightItems = item.querySelectorAll("a.a-expander-header .a-row .a-text-right"); | |
if (rightItems.length != 1) { | |
throw 'rightItems is not equal to 1.\n' + item.innerText; | |
} | |
amount = rightItems[0].innerText; | |
deposit = '', withdrawl = ''; | |
if (amount.includes('-')) { | |
withdrawl = amount.replaceAll('- ₹', ''); | |
} else if (amount.includes('+')) { | |
deposit = amount.replaceAll('+ ₹', ''); | |
} else if (amount.includes('Failed')) { | |
deposit = amount.replaceAll('₹', '').replaceAll('\nFailed',''); | |
} else { | |
throw 'issue with amount: ' + amount + '.\n' + item.innerText; | |
} | |
detailItems = item.querySelectorAll("div.a-row.pad-mini-details-text"); | |
description += ' | Details: '; | |
for (const detailItem of detailItems) { | |
description += '\n - ' + detailItem.innerText.trim().replaceAll(/\s{2,}/g, ' ').replaceAll(/\n+/g, ' - '); | |
} | |
csv += '"' + [dateTime, deposit, withdrawl, description].join('","') + '"\n'; | |
}); | |
file = new Blob([csv], {type: 'text/csv'}); | |
a = document.createElement("a"), url = URL.createObjectURL(file); | |
a.href = url; | |
a.download = new Date().getFullYear()+'-# AMAZONPAY-9624799165 ddmmmyyyy-ddmmmyyyy.csv'; | |
document.body.appendChild(a); | |
a.click(); | |
setTimeout(function () {document.body.removeChild(a);window.URL.revokeObjectURL(url);}, 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Amazon Pay Url
https://www.amazon.in/pay/history?tab=ALL&filter={%22paymentInstruments%22:[{%22paymentInstrumentType%22:%22NETBANKING%22},{%22paymentInstrumentType%22:%22GC%22},{%22paymentInstrumentType%22:%22AMAZON_CREDIT%22},{%22paymentInstrumentType%22:%22SVA%22},{%22paymentInstrumentType%22:%22APV%22,%22paymentInstrumentIds%22:null}],%22dateRanges%22:[{%22from%22:%222023-05-01%22,%22to%22:%222023-06-30%22}]}