summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorBradley M. Kuhn <bkuhn@ebb.org>2012-11-25 13:26:01 -0500
committerBradley M. Kuhn <bkuhn@ebb.org>2012-11-26 13:54:47 -0500
commit4f8ea18fec539c6b2e48fa7125bceaa795e899de (patch)
tree4bc5c3de717f6cbcf7b89686af8b0796a13f68cb /contrib
parent4318c11fd9b94a3508fac7cd7724407f2f7f6645 (diff)
downloadfork-ledger-4f8ea18fec539c6b2e48fa7125bceaa795e899de.tar.gz
fork-ledger-4f8ea18fec539c6b2e48fa7125bceaa795e899de.tar.bz2
fork-ledger-4f8ea18fec539c6b2e48fa7125bceaa795e899de.zip
Support selection of string encoding.
Allow command line option that permits specification of string encoding, passed to Python's unicode() function.
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/non-profit-audit-reports/csv2ods.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/contrib/non-profit-audit-reports/csv2ods.py b/contrib/non-profit-audit-reports/csv2ods.py
index 59571280..2b3024d4 100755
--- a/contrib/non-profit-audit-reports/csv2ods.py
+++ b/contrib/non-profit-audit-reports/csv2ods.py
@@ -31,7 +31,7 @@ def err(msg):
print 'error: %s' % msg
sys.exit(1)
-def csv2ods(csvname, odsname, verbose = False):
+def csv2ods(csvname, odsname, encoding='', verbose = False):
if verbose:
print 'converting from %s to %s' % (csvname, odsname)
doc = ooolib2.Calc()
@@ -56,6 +56,8 @@ def csv2ods(csvname, odsname, verbose = False):
if len(fields) > 0:
for col in range(len(fields)):
val = fields[col]
+ if encoding != '':
+ val = unicode(val, 'utf8')
if len(val) > 0 and val[0] == '$':
doc.set_cell_value(col + 1, row, 'currency', val[1:])
else:
@@ -92,6 +94,8 @@ def main():
help='csv file to process')
parser.add_option('-o', '--ods', action='store',
help='ods output filename')
+ parser.add_option('-e', '--encoding', action='store',
+ help='unicode character encoding type')
(options, args) = parser.parse_args()
if len(args) != 0:
parser.error("not expecting extra args")
@@ -104,7 +108,8 @@ def main():
print '%s: verbose mode on' % program
print 'csv:', options.csv
print 'ods:', options.ods
- csv2ods(options.csv, options.ods, options.verbose)
+ print 'ods:', options.encoding
+ csv2ods(options.csv, options.ods, options.verbose, options.encoding)
if __name__ == '__main__':
main()