From d3fe1c6f5fdc3697aeeb87c0dfb4c94738bcb12d Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Fri, 26 Mar 2021 15:35:22 -0400 Subject: [PATCH] Remove obsolete gnucash Python scripts --- gnucash-convert-account-report-to-csv | 62 --------------- gnucash-process-report | 110 -------------------------- 2 files changed, 172 deletions(-) delete mode 100755 gnucash-convert-account-report-to-csv delete mode 100755 gnucash-process-report diff --git a/gnucash-convert-account-report-to-csv b/gnucash-convert-account-report-to-csv deleted file mode 100755 index 36abf44..0000000 --- a/gnucash-convert-account-report-to-csv +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env python - -# Author: Josh Holtrop -# Date: 2012-10-28 -# Purpose: Convert a HTML "Account Report" output from gnucash to csv format -# Usage: gnucash-convert-account-report-to-csv acount.html > acount.csv - -import os -import sys -import re - -def filter_contents(s): - while True: - new_s = re.sub(r'<[^<>]*>', '', s) - if new_s == s: - break; - s = new_s - return s.replace(',', '').replace('$', '').strip() - -def slurp_row(fh, rows): - row = [] - contents = '' - in_cell = False - for line in iter(fh.readline, ''): - if re.search(r'<\/tr\s*>', line): - rows.append(row) - return True - m = re.search(r']*>(.*)<\/t[hd]>', line) - if m is not None: - row.append(filter_contents(m.group(1))) - continue - m = re.search(r']*>(.*)$', line) - if m is not None: - in_cell = True - contents = m.group(1) - continue - m = re.match(r'(.*)<\/t[hd]>', line) - if m is not None: - contents += m.group(1) - row.append(filter_contents(contents)) - in_cell = False - continue - if in_cell: - contents += line - return False - -def main(argv): - if len(argv) < 2: - sys.stderr.write("Error: specify input HTML file\n") - return -2 - rows = [] - fh = open(argv[1], 'r') - while slurp_row(fh, rows): - pass - fh.close() - for r in rows: - if len(r) == 8: - sys.stdout.write(','.join(r)) - sys.stdout.write('\n') - -if __name__ == '__main__': - sys.exit(main(sys.argv)) diff --git a/gnucash-process-report b/gnucash-process-report deleted file mode 100755 index 20675d8..0000000 --- a/gnucash-process-report +++ /dev/null @@ -1,110 +0,0 @@ -#!/usr/bin/python - -# Josh Holtrop -# 2011-05-07 -# This script processes a cash flow HTML report output by gnucash and -# consolidates the in/out amounts into net amounts and writes a new -# HTML report file to standard output. -# Usage: -# gnucash-process-report generated.html > new.html - -import sys -import re - -def main(argv): - if len(argv) < 2: - sys.stderr.write('Usage: %s \n' % argv[0]) - return 2 - title = '' - accounts = {} - inout = '' - category = '' - f = open(argv[1], 'r') - lines = f.read().split('\n') - f.close() - for line in lines: - m = re.search(r'

(.*)

', line) - if m is not None: - title = m.group(1) - continue - m = re.search(r'Money into', line) - if m is not None: - inout = 'in' - continue - m = re.search(r'Money out of', line) - if m is not None: - inout = 'out' - continue - m = re.search(r'(.*)', line) - if m is not None: - category = m.group(1) - continue - m = re.search(r'', line) - if m is not None: - category = '' - continue - m = re.search(r'number-cel.*>(.*)', line) - if m is not None: - amt = float(re.sub(r'[$,]', '', m.group(1).strip())) - if category != '': - if inout == 'in': - amt = -amt - elif inout != 'out': - continue - if category in accounts: - accounts[category] += amt - else: - accounts[category] = amt - categories = accounts.keys() - categories.sort() - def fmt_amt(a): - f = '%.2f' % a - m = re.match(r'(.+)(...\...)', f) - if m is not None: - f = '%s,%s' % (m.group(1, 2)) - return '$%s' % f - sys.stdout.write(''' - - - %s - - -

%s

-
Money Into Accounts
- -''' % (title, title)) - total_in = 0.0 - for c in categories: - if accounts[c] < 0: - amt = -accounts[c] - total_in += amt - sys.stdout.write('\n' % - (c, fmt_amt(amt))) - sys.stdout.write('' - '\n' % fmt_amt(total_in)) - sys.stdout.write(''' -
%s%s
Total:%s
-
Money Out Of Accounts
- ''') - total_out = 0.0 - for c in categories: - if accounts[c] >= 0: - amt = accounts[c] - total_out += amt - sys.stdout.write('\n' % - (c, fmt_amt(amt))) - sys.stdout.write('' - '\n' % fmt_amt(total_out)) - total_diff = total_in - total_out - sys.stdout.write('\n') - sys.stdout.write('' - '\n' % fmt_amt(total_diff)) - sys.stdout.write(''' -
%s%s
Total:%s
  
Net In:%s
- - -''') - return 0 - -if __name__ == "__main__": - main(sys.argv)