Exemple #1
0
    def retrieveAndSave(self):
        client = FinTS3PinTanClient(
            self.config["fints"]["blz"],  # Your bank's BLZ
            self.config["fints"]["account"],  # your account number
            self.config["fints"]["password"],
            # e.g. 'https://fints.ing-diba.de/fints/'
            self.config["fints"]["endpoint"])

        retriever = TRetriever(client, self.config["fints"]["selectedAccount"])
        converter = CsvConverter(self.config["fints"]["csv_separator"])

        csv_output = "\n".join(
            map(
                lambda transaction: converter.convert(transaction),
                retriever.get_hbci_transactions(self.config["fints"]["start"],
                                                Date.today())))

        with open(self.config["files"]["csv_file"], 'w') as f:
            f.write(converter.get_headline())
            f.write("\n")
            f.write(csv_output)
Exemple #2
0
    def get_config(self):
        parser = argparse.ArgumentParser(
            description='Converting transactions from fints apis to ledger.')
        parser.add_argument(
            '--no-csv',
            dest='convert_to_csv',
            action='store_const',
            const=False,
            default=True,
            help='exclude conversion from fints to csv (default: not excluded)'
        )
        parser.add_argument(
            '--no-ledger',
            dest='convert_to_ledger',
            action='store_const',
            const=False,
            default=True,
            help='exclude conversion from csv to ledger (default: not excluded)'
        )
        parser.add_argument(
            '--csv-file',
            dest='csvfile',
            action='store',
            default="transactions.csv",
            help=
            'file to store/load csv transactions to/from (default: transactions.csv)'
        )
        parser.add_argument(
            '--ledger-file',
            dest='ledgerfile',
            action='store',
            default="journal.ledger",
            help='file to store ledger entries to (default: ledger.journal)')
        parser.add_argument(
            '--files-path',
            dest='files_path',
            action='store',
            default="~/.config/fints2ledger/",
            help=
            'directory to store fints2ledger files (like config.yml) (default: ~/.config/fints2ledger/)'
        )
        parser.add_argument(
            '--date',
            dest='start',
            action='store',
            default=None,
            help=
            'start date to pull the FinTS entries from (format: 2017/12/31 or 17/12/31, default: last year)'
        )
        parser.add_argument(
            '--separator',
            dest='separator',
            action='store',
            default=";",
            help='character used as separator in csv file (default: ;)')
        parser.add_argument(
            '--csv_date_format',
            dest='csv_date_format',
            action='store',
            default='%Y/%m/%d',
            help=
            'Date format used in the donwloaded csv (and subsequently the ledger file). hledger supports 3 date formats (https://hledger.org/1.9/journal.html#simple-dates). Format needs to be compatible with pythons strftime(), see https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior (fints.csv_date_format in config.yml) (default: %%Y/%%m/%%d)'
        )
        args = parser.parse_args()
        command_line_config = {
            "fints": {
                "start":
                utils.date_string_to_mt940_date(args.start)
                if args.start else Date(Date.today().year - 1,
                                        Date.today().month,
                                        Date.today().day),
                "csv_separator":
                args.separator,
                "csv_date_format":
                args.csv_date_format,
                "convert_to_csv":
                args.convert_to_csv
            },
            "ledger": {
                "convert_to_ledger": args.convert_to_ledger
            },
            "files": {
                "csv_file": os.path.expanduser(args.csvfile),
                "ledger_file": os.path.expanduser(args.ledgerfile),
                "files_path": os.path.expanduser(args.files_path)
            }
        }

        self.files_path = command_line_config["files"]["files_path"]

        self.setup_files()
        config = self.load_config_file()

        if not "selectedAccount" in config["fints"]:
            config["fints"]["selectedAccount"] = config["fints"]["account"]

        return utils.update_dict(command_line_config, config)
Exemple #3
0
    def get_config(self):
        parser = argparse.ArgumentParser(
            description='Converting transactions from fints apis to ledger.')
        parser.add_argument(
            '--no-csv',
            dest='convert_to_csv',
            action='store_const',
            const=False,
            default=True,
            help='exclude conversion from fints to csv (default: not excluded)'
        )
        parser.add_argument(
            '--no-ledger',
            dest='convert_to_ledger',
            action='store_const',
            const=False,
            default=True,
            help='exclude conversion from csv to ledger (default: not excluded)'
        )
        parser.add_argument(
            '--csv-file',
            dest='csvfile',
            action='store',
            default="transactions.csv",
            help=
            'file to store/load csv transactions to/from (default: transactions.csv)'
        )
        parser.add_argument(
            '--ledger-file',
            dest='ledgerfile',
            action='store',
            default="journal.ledger",
            help='file to store ledger entries to (default: ledger.journal)')
        parser.add_argument(
            '--date',
            dest='start',
            action='store',
            default=None,
            help=
            'start date to pull the FinTS entires from (fromat: 2017/12/31 or 17/12/31, default: last year)'
        )
        parser.add_argument(
            '--separator',
            dest='separator',
            action='store',
            default=";",
            help='character used as separator in csv file (default: ;)')
        args = parser.parse_args()
        command_line_config = {
            "fints": {
                "start":
                utils.date_string_to_mt940_date(args.start)
                if args.start else Date(Date.today().year - 1,
                                        Date.today().month,
                                        Date.today().day),
                "csv_separator":
                args.separator,
                "convert_to_csv":
                args.convert_to_csv
            },
            "ledger": {
                "convert_to_ledger": args.convert_to_ledger
            },
            "files": {
                "csv_file": args.csvfile,
                "ledger_file": args.ledgerfile
            }
        }

        self.setup_files()
        config = self.load_config_file()

        return utils.update_dict(config, command_line_config)