A python script to convert an ucompressed Gnucash XML file to a text file for Ledger and hledger.

Overview

README

1 gnucash2ledger

gnucash2ledger is a Python script based on the Github Gist by nonducor (nonducor/gcash2ledger.py). This Python script will take an uncompressed Gnucash file saved in the default XML format and write a text file in a format compatible with John Wiegley’s ledger program (Github: ledger/ledger).

Note: gnucash2ledger will only work if the Gnucash data is saved in an uncompressed XML file. If you prefer to save your Gnucash in SQL database formats, checkout the piecash project.

1.1 Features

gnucash2ledger has the following features:

  • Allows for export to a text file or prints results to standard output
  • Exports commodity definitions, account definitions, and transactions with splits
  • Supports multiple commodities/currencies
  • Provides and option to insert a default header for Emacs ledger-mode (Github: ledger/ledger-mode)
  • Currency codes can be replaced by currency symbols using Python CurrencySymbols library
  • Provides an option to display progress bars (useful for converting very long Gnucash files)

1.2 Usage

gnucash2ledger.py [-h] [-c] [-d DATE_FORMAT] [-e] [-f] [-na] [-nc] [-nt] [-o FILENAME] [-p] [--payee-metadata] [-s] [-v] input

1.2.1 Command Line Arguments

Output from gnucash2ledger -h

positional arguments:
  input                 a Gnucash XML file to be read

optional arguments:
  -h, --help            show this help message and exit
  -c, --cleared         Marks all transactions as cleared and place a cleared (*) mark before the transaction heading.
  -d DATE_FORMAT, --date-format DATE_FORMAT
                        A string representing the desired format of dates in the ledger file. Defaults to the ISO standard format: '%Y-%m-%d'.
  -e, --emacs-header    Adds a default header for ledger-mode in Emacs.
  -f, --force-clobber   Force clobbering of and output file i the file already exists. If this option is provided, the output file will overwrite the existing file
                        with the same name.
  -na, --no-account-defs
                        Prevents output of account definitions to the output file.
  -nc, --no-commodity-defs
                        Prevent output of commodities to the output file.
  -nt, --no-transations
                        Prevent output of transactions to the output file. NOTE: This will cause ledger to throw an error if executed on this file.
  -o FILENAME, --output FILENAME
                        Name of file to store the output results.
  -p, --show-progress   Show script status progress while reading and writing data.
  --payee-metadata      Takes the information entered into the 'Description' field in Gnucash splits and adds them as a tagged '; Payee:' memo for the corresponding
                        transaction split.
  -s, --use-symbols     Replaces currency codes with currency symbols.
  -v, --version         show program's version number and exit

1.3 Requirements

gnucash2ledger requires that the following Python packages are installed:

  • currency-symbols
  • tqdm
You might also like...
A simple Python code that takes input from a csv file and makes it into a vcf file.

Contacts-Maker A simple Python code that takes input from a csv file and makes it into a vcf file. Imagine a college or a large community where each y

Automatically generates a TypeQL script for doing entity and relationship insertions from a .csv file, so you don't have to mess with writing TypeQL.
Automatically generates a TypeQL script for doing entity and relationship insertions from a .csv file, so you don't have to mess with writing TypeQL.

Automatically generates a TypeQL script for doing entity and relationship insertions from a .csv file, so you don't have to mess with writing TypeQL.

Search for files under the specified directory. Extract the file name and file path and import them as data.

Search for files under the specified directory. Extract the file name and file path and import them as data. Based on that, search for the file, select it and open it.

The best way to convert files on your computer, be it .pdf to .png, .pdf to .docx, .png to .ico, or anything you can imagine.
The best way to convert files on your computer, be it .pdf to .png, .pdf to .docx, .png to .ico, or anything you can imagine.

The best way to convert files on your computer, be it .pdf to .png, .pdf to .docx, .png to .ico, or anything you can imagine.

Various converters to convert value sets from CSV to JSON, etc.

ValueSet Converters Tools for converting value sets in different formats. Such as converting extensional value sets in CSV format to JSON format able

File-manager - A basic file manager, written in Python

File Manager A basic file manager, written in Python. Installation Install Pytho

gitfs is a FUSE file system that fully integrates with git - Version controlled file system

gitfs is a FUSE file system that fully integrates with git. You can mount a remote repository's branch locally, and any subsequent changes made to the files will be automatically committed to the remote.

This is a file deletion program that asks you for an extension of a file (.mp3, .pdf, .docx, etc.) to delete all of the files in a dir that have that extension.
This is a file deletion program that asks you for an extension of a file (.mp3, .pdf, .docx, etc.) to delete all of the files in a dir that have that extension.

FileBulk This is a file deletion program that asks you for an extension of a file (.mp3, .pdf, .docx, etc.) to delete all of the files in a dir that h

Small-File-Explorer - I coded a small file explorer with several options
Small-File-Explorer - I coded a small file explorer with several options

Petit explorateur de fichier / Small file explorer Pour la première option (création de répertoire) / For the first option (creation of a directory) e

Comments
  • Updated script to include a LedgerConvertor class and improvements

    Updated script to include a LedgerConvertor class and improvements

    This pull request has accomplished the following:

    1. The main method has been simplified as it now uses a call() function from a newly created LedgerConvertor class instead of calling a method convert2ledger.
    2. The classes Commodity, Account, Transaction, and Split all now have a str() function which will output readable text in Ledger format instead of using a toLedgerFormat method for each.
    3. The docstrings have been updated.
    4. The README.org file has been updated with an added "Future" section.
    opened by tfree87 0
  • gnucash2ledger: -s option triggers AttributeError: 'NoneType' object has no attribute 'upper'

    gnucash2ledger: -s option triggers AttributeError: 'NoneType' object has no attribute 'upper'

    If invoked with -s gnucash2ledger emits the following error. The attached patch "fixes" the problem in that the -s functionality now works, but I'm sure it's not the proper soution. I'm not a python programmer but I'm guessing it's some kind of type mismatch with "None".

    Error

    Traceback (most recent call last):
      File "/Users/john/rwfin/2022/gnucash2ledger.py", line 791, in <module>
        main()
      File "/Users/john/rwfin/2022/gnucash2ledger.py", line 778, in main
        convertor = LedgerConvertor(args)
      File "/Users/john/rwfin/2022/gnucash2ledger.py", line 482, in __init__
        self.gcashData = GnucashData(
      File "/Users/john/rwfin/2022/gnucash2ledger.py", line 453, in __init__
        Account(self.accountDb, acc, useSymbols=useSymbols)
      File "/Users/john/rwfin/2022/gnucash2ledger.py", line 120, in __init__
        self.commodity = get_currency_symbol(
      File "/Users/john/rwfin/2022/gnucash2ledger.py", line 594, in get_currency_symbol
        return CurrencySymbols.get_symbol(currency_code) or currency_code
      File "/opt/local/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/currency_symbols/currency_symbols.py", line 23, in get_symbol
        return CURRENCY_SYMBOLS_MAP.get(currency.upper(), None)
    AttributeError: 'NoneType' object has no attribute 'upper'
    

    Patch

    currency_code.diff.txt

    opened by jmarshallidau 0
  • gnucash2ledger: ledger Error: Only one posting with null amount allowed per transaction

    gnucash2ledger: ledger Error: Only one posting with null amount allowed per transaction

    gnucash2ledger formats entries with a minimum single space between the account name and the amount. When this minimum is reached due to long account:sub-account strings, ledger complains and will not report. The attached patch increases the delimiter between account name and amount to a minimum of two spaces.

    NOTE: This is a requirement of the ledger format. https://www.ledger-cli.org/3.0/doc/ledger3.html#The-Most-Basic-Entry

    There must be at least two spaces, or a tab, between the amount and the account. If you do not have adequate separation between the amount and the account Ledger will give an error and stop calculating.

    Ledger Error

    While parsing file "/Users/john/rwfin/2022/fred.ledger", line 24:
    Error: Only one posting with null amount allowed per transaction
    While parsing file "/Users/john/rwfin/2022/fred.ledger", line 36:
    Error: Only one posting with null amount allowed per transaction
    

    Sample Data

    22:2012-06-30 Reconcile to Asset Register - Disposal of Assets 30/06/2011
    23-    ASSETS:NON-CURRENT ASSETS:Communications Equipment:Comm's Equip. Accum. Dep 5,132.00 AUD
    24-    ASSETS:NON-CURRENT ASSETS:Communications Equipment:Comm's Equip. at Cost -5,132.00 AUD
    25-
    --
    34:2012-06-30 Reconcile to Asset Register - Disposal of Assets 30/06/2011
    35-    ASSETS:NON-CURRENT ASSETS:Computer Hardware:Computer H/W Accum. Dep. 61,319.19 AUD
    36-    ASSETS:NON-CURRENT ASSETS:Computer Hardware:Computer H/W at Cost -61,319.19 AUD
    37-
    

    Patch

    null_amount.diff.txt

    opened by jmarshallidau 0
  • gnucash2ledger: AttributeError: 'Split' object has no attribute 'getAccount'

    gnucash2ledger: AttributeError: 'Split' object has no attribute 'getAccount'

    The attached patch addresses the following error.

    Error

    Traceback (most recent call last):
      File "/Users/john/rwfin/2022/gnucash2ledger.py", line 791, in <module>
        main()
      File "/Users/john/rwfin/2022/gnucash2ledger.py", line 785, in main
        print(convertor())
      File "/Users/john/rwfin/2022/gnucash2ledger.py", line 563, in __call__
        results += self.add_transactions()
      File "/Users/john/rwfin/2022/gnucash2ledger.py", line 532, in add_transactions
        results += str(t)
      File "/Users/john/rwfin/2022/gnucash2ledger.py", line 355, in __str__
        splits = "\n".join(str(s) for s in self.splits)
      File "/Users/john/rwfin/2022/gnucash2ledger.py", line 355, in <genexpr>
        splits = "\n".join(str(s) for s in self.splits)
      File "/Users/john/rwfin/2022/gnucash2ledger.py", line 241, in __str__
        destCmdty=self.getAccount().commodity,
    AttributeError: 'Split' object has no attribute 'getAccount'. Did you mean: 'get_account'?
    

    Patch

    get_account.diff.txt

    opened by jmarshallidau 0
Owner
Thomas Freeman
Thomas Freeman
Two scripts help you to convert csv file to md file by template

Two scripts help you to convert csv file to md file by template. One help you generate multiple md files with different filenames from the first colume of csv file. Another can generate one md file with several blocks.

null 2 Oct 15, 2022
csv2ir is a script to convert ir .csv files to .ir files for the flipper.

csv2ir csv2ir is a script to convert ir .csv files to .ir files for the flipper. For a repo of .ir files, please see https://github.com/logickworkshop

Alex 38 Dec 31, 2022
Convert All TXT Files To One File.

AllToOne Convert All TXT Files To One File. Hi ?? , I'm Alireza A Python Developer Boy ?? I’m currently working on my C# projects ?? I’m currently Lea

null 4 Jun 7, 2022
Extract an archive file (zip file or tar file) stored on AWS S3

S3 Extract Extract an archive file (zip file or tar file) stored on AWS S3. Details Downloads archive from S3 into memory, then extract and re-upload

Evan 1 Dec 14, 2021
Python Fstab Generator is a small Python script to write and generate /etc/fstab files based on yaml file on Unix-like systems.

PyFstab Generator PyFstab Generator is a small Python script to write and generate /etc/fstab files based on yaml file on Unix-like systems. NOTE : Th

Mahdi 2 Nov 9, 2021
Vericopy - This Python script provides various usage modes for secure local file copying and hashing.

Vericopy This Python script provides various usage modes for secure local file copying and hashing. Hash data is captured and logged for paths before

null 15 Nov 5, 2022
This simple python script pcopy reads a list of file names and copies them to a separate folder

pCopy This simple python script pcopy reads a list of file names and copies them to a separate folder. Pre-requisites Python 3 (ver. > 3.6) How to use

Madhuranga Rathnayake 0 Sep 3, 2021
A python script generate password files in plain text

KeePass (or any desktop pw manager?) Helper WARNING: This script will generate password files in plain text. ITS NOT SECURE. I needed help remembering

Eric Thomas 1 Nov 21, 2021
Small Python script to generate a calendar (.ics) file from SIMASTER courses schedule.

simaster.ics Small Python script to generate a calendar (.ics) file from SIMASTER courses schedule. Usage Getting the events.json file from SIMASTER O

Faiz Jazadi 8 Nov 2, 2022
Python package to read and display segregated file names present in a directory based on type of the file

tpyfilestructure Python package to read and display segregated file names present in a directory based on type of the file. Installation You can insta

Tharun Kumar T 2 Nov 28, 2021