;bin:simplefincsv: clean up excessive spaces
This commit is contained in:
parent
91b24df4b2
commit
f2d2135ed8
@ -14,7 +14,8 @@ by the given regular expression, print CSV records to stdout:
|
|||||||
2. a field headings record: "date","amount","description","payee","memo","id"
|
2. a field headings record: "date","amount","description","payee","memo","id"
|
||||||
3. any transaction records, in date order.
|
3. any transaction records, in date order.
|
||||||
|
|
||||||
Also if the JSON includes error messages, they will be displayed on stderr,
|
Excess whitespace (more than single spaces) will be trimmed.
|
||||||
|
Also, if the JSON includes error messages, they will be displayed on stderr,
|
||||||
and the exit code will be non-zero.
|
and the exit code will be non-zero.
|
||||||
|
|
||||||
Requirements:
|
Requirements:
|
||||||
@ -51,6 +52,11 @@ def parse_options():
|
|||||||
sys.exit()
|
sys.exit()
|
||||||
return opts, args
|
return opts, args
|
||||||
|
|
||||||
|
# Limit spaces to at most a single space.
|
||||||
|
def clean(txt):
|
||||||
|
return re.sub(r' +', ' ', txt)
|
||||||
|
#return re.sub(r' +', ' ', txt)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
opts, args = parse_options()
|
opts, args = parse_options()
|
||||||
infile = args[0] if len(args) > 0 else '-'
|
infile = args[0] if len(args) > 0 else '-'
|
||||||
@ -61,8 +67,8 @@ def main():
|
|||||||
w = csv.writer(out, quoting=csv.QUOTE_ALL)
|
w = csv.writer(out, quoting=csv.QUOTE_ALL)
|
||||||
|
|
||||||
for a in j['accounts']:
|
for a in j['accounts']:
|
||||||
oname = a['org']['name']
|
oname = clean(a['org']['name'])
|
||||||
aname = a['name']
|
aname = clean(a['name'])
|
||||||
aid = a['id']
|
aid = a['id']
|
||||||
if r and not r.search(f"{oname} {aname} {aid}"): continue
|
if r and not r.search(f"{oname} {aname} {aid}"): continue
|
||||||
|
|
||||||
@ -74,7 +80,7 @@ def main():
|
|||||||
aname,
|
aname,
|
||||||
aid,
|
aid,
|
||||||
a['balance'],
|
a['balance'],
|
||||||
a['currency']
|
clean(a['currency'])
|
||||||
])
|
])
|
||||||
w.writerow([
|
w.writerow([
|
||||||
"date",
|
"date",
|
||||||
@ -91,9 +97,9 @@ def main():
|
|||||||
dt.strftime('%Y-%m-%d'), # %H:%M:%S %Z'),
|
dt.strftime('%Y-%m-%d'), # %H:%M:%S %Z'),
|
||||||
t['id'],
|
t['id'],
|
||||||
t['amount'],
|
t['amount'],
|
||||||
t['description'],
|
clean(t['description']),
|
||||||
t['payee'],
|
clean(t['payee']),
|
||||||
t['memo']
|
clean(t['memo'])
|
||||||
])
|
])
|
||||||
|
|
||||||
errors = j['errors']
|
errors = j['errors']
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user