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 34 35 36 37
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os.path
import click
import logging
from ofxstatement.ofx import OfxWriter
from ofxstatement.plugins import paypal
@click.command()
@click.argument('path')
@click.option('--debug', is_flag=True, default=False)
def convert(path, debug):
"""Parse and print transactions from PayPal's *.csv files."""
logging.basicConfig(level=logging.INFO, format='[%(levelname)s] %(message)s')
root, ext = os.path.splitext(path)
output_file = root + '.ofx'
parser = paypal.PayPalPlugin(ui=None, settings=None).get_parser(path)
statement = parser.parse()
if debug:
for line in statement.lines:
print(line)
return
with open(output_file, 'w') as out:
writer = OfxWriter(statement)
out.write(writer.toxml())
if __name__ == '__main__':
convert()
|