Convert .csv to .dat for generate repot with Python

1,078 views
Skip to first unread message

fa...@itprovent.co.cc

unread,
Apr 10, 2013, 4:31:02 AM4/10/13
to ledge...@googlegroups.com
Hello, 
I want to convert .csv to .dat for generate repot with Python.
Can python use ledger's module to convert and keep the report in python's object?

Zack Williams

unread,
Apr 10, 2013, 10:27:08 AM4/10/13
to ledge...@googlegroups.com
On Wed, Apr 10, 2013 at 1:31 AM, <fa...@itprovent.co.cc> wrote:
Hello, 
I want to convert .csv to .dat for generate repot with Python.

There are a lot (5+) of ways to convert CSV to ledger format via scripts. 
 
Can python use ledger's module to convert and keep the report in python's object?

As text?  I think you need to walk the ledger object to get the data out. 

You might be better off running ledger from within the script and parsing it's output, depending on what you want.

- Zack 




fa...@itprovent.co.cc

unread,
Apr 10, 2013, 11:28:35 PM4/10/13
to ledge...@googlegroups.com

i've run ledger using python, 
but i still don't know what ledger's module to convert .csv to journal in python

Could you give me some example to convert csv using pyhton?

what i've done so far, demo.py:
import MySQLdb
import csv
import os
import ledger
con = MySQLdb.connect("localhost", "root", "123123", "test")
cur = con.cursor()
query = "select * from transaction"
try:
cur.execute(query)
result = cur.fetchall()
fp = open("demo-data2.csv", "w")
file = csv.writer(fp)
header = ["transid", "date", "payee", "note", "amount", "", "", "code", ""]
file.writerow(header)
file.writerows(result)
fp.close()
except:
print("Error: Enable to connect database")
con.close()
os.system("ledger -f /dev/null convert demo-data2.csv --input-date-format %m/%d/%Y -o demo-data2.dat")
os.system("ledger -f demo-data2.dat b -o demo-data2.txt")
Message has been deleted

Craig Earls

unread,
Apr 12, 2013, 9:02:59 AM4/12/13
to ledge...@googlegroups.com

The python interface is very immature. I don't think anyone has tried  what youvatecattempting


Sent from Mailbox for iPhone


On Thu, Apr 11, 2013 at 10:05 PM, fa...@itprovent.co.cc <fa...@itprovent.co.cc> wrote:

help please?

--
 
---
You received this message because you are subscribed to the Google Groups "Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ledger-cli+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

fa...@itprovent.co.cc

unread,
Apr 13, 2013, 1:35:14 AM4/13/13
to ledge...@googlegroups.com
Is there any documentation about python interface?
At least I can try it. 

When the python interface can work properly?
Reply all
Reply to author
Forward
0 new messages