

import requests
import json
import re
displayname = 'theralphretort'
after = '99999999999'
csv = open(displayname + '-earnings.csv', 'w')
csv.write('id,sender,recipient,amount,timestamp\n')
pattern = re.compile('@([^\s]+) donated (\d+) LEMON\(s\) to post ([^\+]+)\+.*')
while after != '':
earnings = json.loads(requests.post('https://graphigo.prd.dlive.tv/',data=
'{"operationName":"LivestreamProfileWallet","variables":{"displayname":"'
+ displayname + '","first":20,"isLoggedIn":false,"after":"' + after + '"},' +
'"extensions":{"persistedQuery":{"version":1,"sha256Hash":' +
'"bea6cdfec46735f1d7510acc1cd0823585dfb7feb6b20ecba886fd678b60c699"}}}').text)
earnings = earnings['data']['userByDisplayName']['transactions']
after = earnings['pageInfo']['endCursor']
for transaction in earnings['list']:
match = pattern.match(transaction['description'])
if bool(match):
csv.write(transaction['seq'] + ',')
csv.write(match.group(1) + ',')
csv.write(match.group(3) + ',')
csv.write(match.group(2) + ',')
csv.write(transaction['createdAt'] + '\n')
csv.close()
