34 lines
1.0 KiB
TypeScript
Raw Normal View History

import { type Actual, ActualImpl } from "@/actual.ts"
import { cronJobDaily } from "@/cron.ts"
import { type Bank, Sparebank1Impl } from "@/sparebank1.ts"
import { transactionIntoActualTransaction } from "@/mappings.ts"
2024-11-15 22:55:53 +01:00
async function daily(actual: Actual, bank: Bank): Promise<() => Promise<void>> {
return async () => {
console.log("Wake up! It's 1 AM!")
// Fetch transactions from the bank
const transactions = await bank.transactionsPastDay(
"my_account",
"my_access_token",
)
2024-11-15 22:55:53 +01:00
// TODO account? id or name?
const actualTransactions = transactions.map((transaction) =>
transactionIntoActualTransaction(transaction, ""),
2024-11-15 22:55:53 +01:00
)
// TODO Import transactions into Actual
// If multiple accounts, loop over them
// Get account ID from mapper
await actual.importTransactions("a-b-c-d-e", actualTransactions)
}
}
2024-11-15 22:55:53 +01:00
async function main(): Promise<void> {
const actual = await ActualImpl.init()
cronJobDaily(await daily(actual, new Sparebank1Impl()))
// await actual.shutdown()
2024-11-15 22:55:53 +01:00
}
void main()