Skip to content

Commit eb9e555

Browse files
committed
Make CSV conversion scripts more robust
1 parent e596ebf commit eb9e555

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

Diff for: scripts/csv2yaml/dkb.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@ async function normalizeAndPrint (filePathTemp) {
4949
? {
5050
transfers: [{
5151
from: "dkb:giro",
52-
to: noteToAccount(transaction.from) || noteToAccount(note),
52+
to: noteToAccount(transaction.to) ||
53+
noteToAccount(transaction.from) || noteToAccount(note),
5354
amount: amount.slice(1),
5455
"original-amount": transaction["original-amount"],
5556
}],
5657
}
5758
: {
5859
transfers: [{
59-
from: noteToAccount(transaction.from) || noteToAccount(note),
60+
from: noteToAccount(transaction.to) ||
61+
noteToAccount(transaction.from) || noteToAccount(note),
6062
to: "dkb:giro",
6163
// TODO: Remove when github.com/adius/csvnorm/issues/1 is solved
6264
amount: transaction.amount === "0,00" ? "0 €" : amount,
@@ -81,9 +83,8 @@ async function normalizeAndPrint (filePathTemp) {
8183
})
8284

8385
csvnorm.default({
84-
encoding: "latin1",
8586
readableStream: fse.createReadStream(filePathTemp),
86-
skipLinesStart: 6,
87+
skipLinesStart: 4,
8788
writableStream: csv2json,
8889
})
8990
}

Diff for: scripts/csv2yaml/paypal.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ async function normalizeAndPrint (filePathTemp) {
2727
.parse(jsonTemp)
2828
.map(keysToEnglish)
2929
.map(transaction => {
30-
const currency = transaction.currency
31-
.replace("EUR", "€")
30+
const currency = transaction?.currency
31+
?.replace("EUR", "€")
3232
.replace("USD", "$")
3333
.trim()
3434

@@ -40,15 +40,15 @@ async function normalizeAndPrint (filePathTemp) {
4040
transaction.time,
4141
transaction.timezone,
4242
].join(" "))
43-
.toISOString()
43+
?.toISOString()
4444
.replace("T", " ")
4545
.replace(".000Z", ""),
4646
note: transaction.subject,
4747
},
4848
transaction,
4949
)
5050
const account = noteToAccount(transaction.name)
51-
const transfer = transaction.gross.startsWith("-")
51+
const transfer = transaction.gross?.startsWith("-")
5252
? {
5353
from: "_todo_:paypal:" +
5454
transaction.currency
@@ -61,7 +61,7 @@ async function normalizeAndPrint (filePathTemp) {
6161
from: account ? account : "paypal",
6262
to: "_todo_:paypal:" +
6363
transaction.currency
64-
.toLowerCase()
64+
?.toLowerCase()
6565
.trim(),
6666
amount: transaction.gross + " " + currency,
6767
}
@@ -75,10 +75,10 @@ async function normalizeAndPrint (filePathTemp) {
7575
newTransaction.transfers.push({
7676
from: "_todo_:paypal:" +
7777
transaction.currency
78-
.toLowerCase()
78+
?.toLowerCase()
7979
.trim(),
8080
to: "paypal",
81-
amount: transaction.fee.slice(1) + " " + currency,
81+
amount: transaction.fee?.slice(1) + " " + currency,
8282
tags: ["fee"],
8383
})
8484
}

Diff for: scripts/helpers.js

+3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export function keysToEnglish (object) {
6363
.replace(/^Auswirkung auf Guthaben$/i, "balance_impact")
6464
.replace(/^Ursprünglicher Betrag$/i, "original-amount")
6565
.replace(/^Versicherungsbetrag$/i, "insurance_amount")
66+
.replace(/^Zahlungsempfänger\*in$/i, "to")
6667
.replace(/^Zahlungsbetrag in ZW$/i, "amount")
6768
.replace(/^Artikelbezeichnung$/i, "item_title")
6869
.replace(/^Zahlungswährung \(ZW\)$/i, "currency")
@@ -96,6 +97,7 @@ export function keysToEnglish (object) {
9697
.replace(/^Buchungstag$/i, "entry-utc")
9798
.replace(/^Depotnummer$/i, "depot-id")
9899
.replace(/^Betrag \(EUR\)$/i, "amount")
100+
.replace(/^Betrag \(\)$/i, "amount")
99101
.replace(/^Buchungstext$/i, "type")
100102
.replace(/^Beschreibung$/i, "note")
101103
.replace(/^Belegdatum$/i, "entry-utc")
@@ -187,6 +189,7 @@ export function noteToAccount (note = "") {
187189
"google": "google",
188190
"free software foundation": "free_software_foundation",
189191
"landr audio": "landr",
192+
"landr studio": "landr",
190193
"mzla technologies": "mzla_technologies",
191194
"vodafone": "vodafone",
192195
"mailgun": "mailgun",

0 commit comments

Comments
 (0)