@fuzzle/opencode-accountant 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +26 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -15121,6 +15121,22 @@ function getYesterday() {
|
|
|
15121
15121
|
d.setDate(d.getDate() - 1);
|
|
15122
15122
|
return d.toISOString().split("T")[0];
|
|
15123
15123
|
}
|
|
15124
|
+
function parsePriceLine(line) {
|
|
15125
|
+
const match = line.match(/^P (\d{4}-\d{2}-\d{2})(?: \d{2}:\d{2}:\d{2})? .+$/);
|
|
15126
|
+
if (!match)
|
|
15127
|
+
return null;
|
|
15128
|
+
return {
|
|
15129
|
+
date: match[1],
|
|
15130
|
+
formattedLine: line
|
|
15131
|
+
};
|
|
15132
|
+
}
|
|
15133
|
+
function filterPriceLinesByDateRange(priceLines, startDate, endDate) {
|
|
15134
|
+
return priceLines.map(parsePriceLine).filter((parsed) => {
|
|
15135
|
+
if (!parsed)
|
|
15136
|
+
return false;
|
|
15137
|
+
return parsed.date >= startDate && parsed.date <= endDate;
|
|
15138
|
+
}).sort((a, b) => a.date.localeCompare(b.date)).map((parsed) => parsed.formattedLine);
|
|
15139
|
+
}
|
|
15124
15140
|
function updateJournalWithPrices(journalPath, newPriceLines) {
|
|
15125
15141
|
let existingLines = [];
|
|
15126
15142
|
if (fs2.existsSync(journalPath)) {
|
|
@@ -15180,15 +15196,23 @@ async function updatePricesCore(directory, agent, backfill, priceFetcher = defau
|
|
|
15180
15196
|
cmdArgs.push("--fmt-base", currencyConfig.fmt_base);
|
|
15181
15197
|
}
|
|
15182
15198
|
const output = await priceFetcher(cmdArgs);
|
|
15183
|
-
const
|
|
15199
|
+
const rawPriceLines = output.split(`
|
|
15184
15200
|
`).filter((line) => line.startsWith("P "));
|
|
15185
|
-
if (
|
|
15201
|
+
if (rawPriceLines.length === 0) {
|
|
15186
15202
|
results.push({
|
|
15187
15203
|
ticker,
|
|
15188
15204
|
error: `No price lines in pricehist output: ${output}`
|
|
15189
15205
|
});
|
|
15190
15206
|
continue;
|
|
15191
15207
|
}
|
|
15208
|
+
const priceLines = filterPriceLinesByDateRange(rawPriceLines, startDate, endDate);
|
|
15209
|
+
if (priceLines.length === 0) {
|
|
15210
|
+
results.push({
|
|
15211
|
+
ticker,
|
|
15212
|
+
error: `No price data found within date range ${startDate} to ${endDate}`
|
|
15213
|
+
});
|
|
15214
|
+
continue;
|
|
15215
|
+
}
|
|
15192
15216
|
const journalPath = path2.join(directory, "ledger", "currencies", currencyConfig.file);
|
|
15193
15217
|
updateJournalWithPrices(journalPath, priceLines);
|
|
15194
15218
|
const latestPriceLine = priceLines[priceLines.length - 1];
|