Пример #1
0
    def parse(self):
        statements = []

        statement_files = list_statement_files(self.input_dir, "pdf")
        if not statement_files:
            logger.error(f"No statement files found.")
            raise SystemExit(1)

        logger.info(
            f"Collected statement files for processing: {statement_files}.")

        for statement_file in statement_files:
            logger.debug(f"Processing statement file[{statement_file}]")

            with open(statement_file, "rb") as fd:
                viewer = SimplePDFViewer(fd)
                activities = self.extract_activities(viewer)
                if not activities:
                    continue
                statements.append(activities)

        statements = sorted(
            statements,
            key=lambda k: k[self.get_first_non_ssp_activity_index(k)][
                "trade_date"])
        return [
            activity for activities in statements for activity in activities
        ]
Пример #2
0
    def parse(self):
        statements = []

        statement_files = list_statement_files(self.input_dir, "csv")
        if not statement_files:
            logger.error(f"No statement files found.")
            raise SystemExit(1)

        logger.info(
            f"Collected statement files for processing: {statement_files}.")

        for statement_file in statement_files:
            logger.debug(f"Processing statement file[{statement_file}]")

            with open(statement_file, "r") as fd:
                viewer = csv.reader(fd, delimiter=",")
                activities = self.extract_activities(viewer)
                if not activities:
                    continue
                statements.append(activities)

        statements = sorted(statements, key=lambda k: k[0]["trade_date"])
        return [
            activity for activities in statements for activity in activities
        ]
Пример #3
0
def main():
    logger.info("Collecting statement files.")
    statement_files = list_statement_files(parsed_args.input_dir)

    if not statement_files:
        logger.error(f"No statement files found.")
        raise SystemExit(1)

    logger.info(
        f"Collected statement files for processing: {statement_files}.")

    logger.info(f"Parsing statement files.")
    statements = parse_statements(statement_files)

    logger.info(f"Generating [statements.csv] file.")
    export_statements(os.path.join(parsed_args.output_dir, "statements.csv"),
                      statements)

    if not statements:
        logger.error(
            f"Not activities found. Please, check your statement files.")
        raise SystemExit(1)

    unsupported_activity_types = get_unsupported_activity_types(statements)
    if unsupported_activity_types:
        logger.error(
            f"Statements contain unsupported activity types: {unsupported_activity_types}. Please, check documentation."
        )
        raise SystemExit(1)

    logger.info(f"Populating exchange rates.")
    populate_exchange_rates(statements, parsed_args.use_bnb)

    logger.info(f"Generating [app8-part1.csv] file.")
    export_app8_part1(os.path.join(parsed_args.output_dir, "app8-part1.csv"),
                      statements)

    logger.info(f"Calculating sales information.")
    sales = calculate_win_loss(statements)

    logger.info(f"Generating [app5-table2.csv] file.")
    export_app5_table2(os.path.join(parsed_args.output_dir, "app5-table2.csv"),
                       sales)

    logger.info(f"Calculating dividends information.")
    dividends = calculate_dividends(statements)

    logger.info(f"Generating [app8-part4-1.csv] file.")
    export_app8_part4_1(
        os.path.join(parsed_args.output_dir, "app8-part4-1.csv"), dividends)

    logger.info(f"Generating [dec50_2020_data.xml] file.")
    export_to_xml(os.path.join(parsed_args.output_dir, "dec50_2020_data.xml"),
                  statements, sales, dividends)

    win_loss = sum(item["profit"] + item["loss"] for item in sales)
    logger.info(f"Profit/Loss: {win_loss} lev.")