File: convert.py

package info (click to toggle)
ofxstatement-plugins 20210310
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,964 kB
  • sloc: python: 7,219; xml: 1,027; makefile: 167; sh: 92
file content (37 lines) | stat: -rwxr-xr-x 868 bytes parent folder | download | duplicates (5)
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()