Exemplo n.º 1
0
def parsed_statements(filepaths, plugins):

    plugin_map = dict(list_plugins())

    for fp in filepaths:
        for pname in plugins:
            plugin = plugin_map[pname](ui.UI(), {
                "account": 000,
                "currency": "€"
            })
            parser = plugin.get_parser(fp)
            yield parser.parse()
Exemplo n.º 2
0
def convert(args: argparse.Namespace) -> int:
    appui = ui.UI()
    config = configuration.read()

    if config is None:
        # No configuration mode
        settings = {}
        pname = args.type
    else:
        # Configuration is loaded
        if args.type not in config:
            log.error("No section '%s' in config file." % args.type)
            log.error(
                "Edit configuration using ofxstatement edit-config and "
                "add section [%s]." % args.type
            )
            return 1  # error

        settings = dict(config[args.type])

        pname = settings.get("plugin", None)
        if not pname:
            log.error("Specify 'plugin' setting for section [%s]" % args.type)
            return 1  # error

    # pick and configure plugin
    try:
        p = plugin.get_plugin(pname, appui, settings)
    except plugin.PluginNotRegistered:
        log.error("No plugin named '%s' is found" % pname)
        return 1  # error

    # process the input and produce output
    parser = p.get_parser(args.input)
    try:
        statement = parser.parse()
    except exceptions.ParseError as e:
        log.error("Parse error on line %s: %s" % (e.lineno, e.message))
        return 2  # parse error

    # Validate the statement
    try:
        statement.assert_valid()
    except exceptions.ValidationError as e:
        log.error("Statement validation error: %s" % (e.message))
        return 2  # Validation error

    with smart_open(args.output, settings.get("encoding", None)) as out:
        writer = ofx.OfxWriter(statement)
        out.write(writer.toxml())

    log.info("Conversion completed: %s" % args.input)
    return 0  # success