AkahuSync/main.py
2026-05-19 11:02:39 +12:00

36 lines
1.5 KiB
Python

from IngestionService.ingester import Ingester
from config import load_env
import os
load_env("IngestionService")
if __name__ == "__main__":
ingester = Ingester()
ingester.test_db_connection()
run_akahu = os.getenv("RUN_AKAHU", "true").strip().lower() in {"1", "true", "yes"}
run_emoney = os.getenv("RUN_EMONEY", "true").strip().lower() in {"1", "true", "yes"}
run_normalize = os.getenv("RUN_NORMALIZE", "true").strip().lower() in {"1", "true", "yes"}
if run_akahu:
akahu_accounts = ingester.fetch_akahu_snapshot_data()
#print("Akahu accounts fetched:", len(akahu_accounts.get("items", [])))
ingester.write_akahu_snapshot_data(akahu_accounts)
#backfill_start = "2026-01-01"
#backfill_end = "2026-12-31"
#akahu_backfill = ingester.backfill_akahu_transactions(backfill_start, backfill_end)
#print("Akahu backfill transactions:", len(akahu_backfill.get("items", [])))
if run_emoney:
emoney_data = ingester.fetch_emoney_data()
emoney_snapshot = emoney_data.get("snapshot") or {"accounts": []}
emoney_transactions = emoney_data.get("transactions") or []
#print("Emoney snapshot accounts:", len(emoney_snapshot.get("accounts", [])))
ingester.write_emoney_snapshot_data(emoney_snapshot)
#print("Emoney transactions:", len(emoney_transactions))
ingester.write_emoney_transaction_data(emoney_transactions)
if run_normalize:
ingester.normalize_pending_data()