1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
from __future__ import absolute_import
from __future__ import unicode_literals
try:
# python 3
from io import StringIO
except ImportError:
# python 2
from StringIO import StringIO
from ofxclient.client import Client
def combined_download(accounts, days=60):
"""Download OFX files and combine them into one
It expects an 'accounts' list of ofxclient.Account objects
as well as an optional 'days' specifier which defaults to 60
"""
client = Client(institution=None)
out_file = StringIO()
out_file.write(client.header())
out_file.write('<OFX>')
for a in accounts:
ofx = a.download(days=days).read()
stripped = ofx.partition('<OFX>')[2].partition('</OFX>')[0]
out_file.write(stripped)
out_file.write("</OFX>")
out_file.seek(0)
return out_file
|