HTML to CSV - Convert Account Summary report to CSV?

mvillarino mvillarino at dubmail.net
Wed Oct 6 11:51:06 EDT 2004


O Xoves 30 Setembro 2004 14:52, BruceG escribiu:
> Hey all,
>
>  I am trying to convert my Account Summary report from HTML to CSV. I am
> using GnuCash 1.8.8 and am completing 9 months worth of transactions after
> tonight's postings hit the bank. What I would like to do is export the
> account summary and start working on a budget based on what I've spent and
> earned year to date. (I know, wrong time of the year to try to stick to a
> budget)
>
>  I googled and saw a post on exactly what I am trying to do here:
> http://www.glorp.org/publicRepository/GnuCash%20Utilities(Bundle).html but
> can't seem to locate the bundle.
>
>  So, anyone have a utility to convert the Account Summary html report to
> csv format for import into OOo Calc or something similar?
>
> Thanks,
> BruceG
> _______________________________________________
> gnucash-user mailing list
> gnucash-user at gnucash.org
> https://lists.gnucash.org/mailman/listinfo/gnucash-user

Uff, you're right, OO.org importing HTML tables is ugly, specialy if it adds a 
"EUR" before each number in cells containing numbers.

So I've done this short python script. It works at least in the EURO zone, and 
in countrys where decimal separator is a comma (,), not a dot (.). I've used 
as values separator a (;), not a comma, due to a problem with accents while 
writting it.

It's strongly based in HTMLParse module documentation, in Python's library 
Reference.

#!/usr/bin/env python
from HTMLParser import HTMLParser

class MyHTMLParser(HTMLParser):
 
 def handle_entityref(self, nome):
  informe.write("")
 def handle_endtag(self, tag):
  # print "Encountered the end of a %s tag" % tag
  if tag=="td":
   informe.write( ";")
  elif tag == 'tr':
   informe.write("\n")

 def handle_data(self, tag):
  if tag != "\n":
   informe.write( tag.replace(".","").replace(",",".").replace("EUR",""))



entrada= str(raw_input("GnuCash HTML report name?"))
saida=str(raw_input("final report name?"))
file = file(entrada, 'r')
informe=open(saida,"w")
parsea= MyHTMLParser()
srt=file.readline()

while srt:
 parsea.feed(srt)
 srt=file.readline()
informe.close()




More information about the gnucash-user mailing list