;bin:simplefincsv: reorder fields, move ids to the end

This commit is contained in:
Simon Michael 2025-08-28 12:21:06 +01:00
parent f2d2135ed8
commit 605444923e

View File

@ -10,9 +10,9 @@ Read SimpleFIN /accounts JSON from JSONFILE or stdin, and for each account with
or just the ones where "ORGNAME ACCTNAME ACCTID" is case-insensitively infix-matched or just the ones where "ORGNAME ACCTNAME ACCTID" is case-insensitively infix-matched
by the given regular expression, print CSV records to stdout: by the given regular expression, print CSV records to stdout:
1. an account info record: "account",ORGNAME,ACCTNAME,ACCTID,BALANCE,CURRENCY 1. an account info record: "account",BALANCE,ORGNAME,ACCTNAME,CURRENCY,ACCTID
2. a field headings record: "date","amount","description","payee","memo","id" 2. a field headings record: "date","amount","payee","description","memo","id"
3. any transaction records, in date order. 3. the transaction records, in date order.
Excess whitespace (more than single spaces) will be trimmed. Excess whitespace (more than single spaces) will be trimmed.
Also, if the JSON includes error messages, they will be displayed on stderr, Also, if the JSON includes error messages, they will be displayed on stderr,
@ -76,30 +76,30 @@ def main():
if ts: if ts:
w.writerow([ w.writerow([
"account", "account",
a['balance'],
oname, oname,
aname, aname,
a['currency'],
aid, aid,
a['balance'],
clean(a['currency'])
]) ])
w.writerow([ w.writerow([
"date", "date",
"id",
"amount", "amount",
"description",
"payee", "payee",
"memo" "description",
"memo",
"id",
]) ])
for t in reversed(a['transactions']): for t in reversed(a['transactions']):
dt = datetime.datetime.fromtimestamp(t['posted']) dt = datetime.datetime.fromtimestamp(t['posted'])
# dtl = dt.astimezone() # dtl = dt.astimezone()
w.writerow([ w.writerow([
dt.strftime('%Y-%m-%d'), # %H:%M:%S %Z'), dt.strftime('%Y-%m-%d'), # %H:%M:%S %Z'),
t['id'],
t['amount'], t['amount'],
clean(t['description']),
clean(t['payee']), clean(t['payee']),
clean(t['memo']) clean(t['description']),
clean(t['memo']),
t['id'],
]) ])
errors = j['errors'] errors = j['errors']