Last active
January 31, 2021 16:16
-
-
Save arafsheikh/9b8e577a9100e68ce96655a76bb78be8 to your computer and use it in GitHub Desktop.
Fetch all Paytm Transactions
This file contains hidden or 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
import json | |
import pandas as pd | |
from requests import get | |
URL = "https://paytm.com/v1/api/wallet/txnhistory?page_size=199&page_number={}" | |
COOKIE = "connect.sid=s%3AofLVI3Sfk29a5WofL892sj6BX0c1ZMgV.tWVDqXZGV3rjZ7g3%2FG4g9FozYcnfblY9Trv8lsuQbKo;" # This is an example. Set this to a valid session cookie. | |
RAW_RESP = [] | |
resp = get(URL.format("0"), headers={"Cookie": COOKIE}).content | |
data = json.loads(resp) | |
RAW_RESP = data['response'] | |
count = 1 | |
while (data['has_next']): | |
resp = get(URL.format(str(count)), headers={"Cookie": COOKIE}).content | |
data = json.loads(resp) | |
RAW_RESP += data['response'] | |
count += 1 | |
USEFUL_RESP = [] | |
for response in RAW_RESP: | |
USEFUL_RESP.append({ | |
"txnamount" : response['txnamount'], | |
"closingBalance" : response['extendedTxnInfo'][0]['closingBalance'], | |
"mode" : response['mode'], | |
"newNarration" : response['newNarration'], | |
"payeeId" : response['payeeId'], | |
"txnDescription1" : response['txnDescription1'], | |
"txnStatus" : response['txnStatus'], | |
"txndate" : response['txndate'], | |
"txntype" : response['txntype'], | |
"type" : response['type'], | |
"walletOrderId" : response['walletOrderId'], | |
"txnFrom" : response['txnFrom'], | |
"txnTo" : response['txnTo'], | |
"totalBalance" : response['totalBalance'], | |
}) | |
df = pd.DataFrame.from_dict(USEFUL_RESP) | |
df.to_csv('transactions.csv') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment