Skip to content

Instantly share code, notes, and snippets.

@chaseadam
Created August 28, 2017 17:54
Show Gist options
  • Save chaseadam/2e97118b29ead8b1549c85133e4f7282 to your computer and use it in GitHub Desktop.
Save chaseadam/2e97118b29ead8b1549c85133e4f7282 to your computer and use it in GitHub Desktop.
Dwolla dump all transactions
#!/bin/python
# Dump all transfers from Dwolla account because they don't provide a downloadable method on the web UI.
# Copyright 2017 Adam Chasen <adam@chasen.name>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import sys
import requests
import json
headers = {'Accept': 'application/vnd.dwolla.v1.hal+json',
'Content-Type': 'application/vnd.dwolla.v1.hal+json',
'Authorization': 'Bearer XXXX'}
def getAll(url):
nextPage = { 'href': url}
items = []
while nextPage:
print nextPage['href']
req = requests.get(nextPage['href'], headers = headers)
content = json.loads(req.content)
if content['_links'].has_key('next'):
nextPage = content['_links']['next']
else:
nextPage = False
embedded = content['_embedded']
assert len(embedded) == 1
items += embedded[embedded.keys()[0]]
return items
req = requests.get('https://api.dwolla.com', headers = headers)
main = json.loads(req.content)
assert len(main) == 1
assert len(main['_links']) == 1
mainAccount = main['_links']['account']['href']
req = requests.get(mainAccount, headers = headers)
mainAccountTransfers = json.loads(req.content)['_links']['transfers']['href']
transfers = getAll(mainAccountTransfers)
accountLinks = set()
transfersExpanded = []
for transfer in transfers:
for k,link in transfer['_links'].iteritems():
if k == 'self':
continue
if 'https://api.dwolla.com/' in link['href']:
req = requests.get(link['href'], headers = headers)
transfer[k] = json.loads(req.content)
else:
transfer[k] = link['href']
transfersExpanded.append(transfer)
with open(sys.argv[1], 'w') as output:
output.write(json.dumps(transfersExpanded, indent=4, separators=(',', ': ')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment