quentinsf <[email protected]> writes:

> So I've created icsv2ledger, which you can find on GitHub at
>
>    https://github.com/quentinsf/icsv2ledger

Quentin,

Thanks!  This promises to fix the biggest productivity problem I have
with ledger: importing credit card statements.  I tried it last night,
and it was easy to set up and use.  I like that it included the original
csv entry as a comment.

Now the suggestions / problems:

- I'm running ledger 2.6.2, as that's what my distro (LMDE) offers.
  icsv2ledger.py would work with that if it put the md5sum and csv
  entries _after_ the real entry, not before.

- To make it work with 2.6.2, it also needs to emit the comments
  starting at the start of the line, not after 4 spaces.

- For those of us trying out new versions as you introduce them, it
  would be nice to put some sort of version information in the file
  header.  I double-checked that I had the latest by downloading the
  current version and running ediff against what I was using, but a
  version string on github and in the file would have saved a minute or
  two.  

- Arrgh.  I just edited the script to fix those problems and then tried
  it on another file, and I found another: my credit card company
  changed from %Y/%m/%d to %m/%d/%Y at some time.  That's probably above
  and beyond the call of duty, but a really smart date parser wouldn't
  be refused. :-)  Lacking that, I'll set up two sections of my
  .icsv2ledger file with the two date formats.

I wouldn't have suggested supporting an older version of ledger if it
didn't seem so easy.  In fact, here's a patch file that should work,
created by

,----
| LC_ALL=C TZ=UTC0 diff -Naur icsv2ledger.py icsv2ledgerBH.py > 
icsv2ledger.patch 
`----

========================================================================

--- icsv2ledger.py      2011-11-13 05:46:22.805973491 +0000
+++ icsv2ledgerBH.py    2011-11-13 16:50:04.160682863 +0000
@@ -5,6 +5,8 @@
 #
 # Requires Python >= 2.5 and Ledger >= 3.0
 
+# 2011/11/13: modified to work with Ledger >= 2.6.2 Bill Harris
+
 import csv, sys, os, json
 import md5, re, subprocess, types
 import readline,rlcompleter
@@ -82,12 +84,12 @@
         """
         out  = "%s * %s\n" % (self.date, payee)
 
-        if output_tags:
-            out += "    ; MD5Sum: %s\n" % self.md5sum
-            out += "    ; CSV: \"%s\"\n" % self.csv
-
         out += "    %-60s%s\n" % (account, ("   " + self.debit) if self.debit 
else "")
         out += "    %-60s%s\n" % (self.csv_account,  ("   " + self.credit) if 
self.credit else "")
+        if output_tags:
+            out += "; MD5Sum: %s\n" % self.md5sum
+            out += "; CSV: \"%s\"\n" % self.csv
+
         return out
         
 
========================================================================

Simply cd to the folder with the 2011/10/30 version of icsv2ledger, and
run

,----
| patch  < icsv2ledger.patch
`----

You might want to make the changes an option, so that you can have the
current 3.0 behavior or the 2.6.x behavior.  OTOH, having it the same
always makes it easier to move between versions of ledger.

I tested this against ledger 2.6.2 only; I only suspect it works with
other versions.

Thanks again for this tool,

Bill
-- 
Bill Harris                  http://makingsense.facilitatedsystems.com/
Facilitated Systems                              Everett, WA 98208 USA
http://www.facilitatedsystems.com/               phone: +1 425 374-1845

Reply via email to