60 lines
2.1 KiB
Python
60 lines
2.1 KiB
Python
#!/usr/bin/env python
|
|
"""Example usage of WellsFargo extraction and transaction processing."""
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
from transaction_processor import TransactionProcessor
|
|
from wf_debit_extractor import WellsFargoPayloadExtractor
|
|
|
|
|
|
def main():
|
|
# Load or extract WellsFargo payloads
|
|
extractor = WellsFargoPayloadExtractor()
|
|
extracted_objects = extractor.extract_from_file("posted.dat")
|
|
|
|
print(f"Extracted {len(extracted_objects)} WellsFargo payload(s)\n")
|
|
|
|
# Process transactions
|
|
processor = TransactionProcessor()
|
|
transactions = processor.extract_transactions(extracted_objects)
|
|
|
|
print(f"Found {len(transactions)} transaction(s)\n")
|
|
|
|
# Display first few transactions
|
|
for i, txn in enumerate(transactions[:5]):
|
|
print(f"Transaction {i + 1}:")
|
|
print(f" ID: {txn['id']}")
|
|
print(
|
|
f" Amount: ${txn['transaction_amount_cents'] / 100:.2f} ({txn['transaction_amount_cents']} cents)"
|
|
)
|
|
print(f" Description: {txn['transaction_description']}")
|
|
print(f" Transaction Date: {txn['transaction_date_datetime']} (ts: {txn['transaction_date_timestamp']})")
|
|
print(f" Post Date: {txn['post_date_datetime']} (ts: {txn['post_date_timestamp']})")
|
|
print()
|
|
|
|
# Optionally save all processed transactions to JSON
|
|
output_file = Path("processed_transactions.json")
|
|
serializable = [
|
|
{
|
|
"id": txn["id"],
|
|
"transaction_amount_cents": txn["transaction_amount_cents"],
|
|
"transaction_date_timestamp": txn["transaction_date_timestamp"],
|
|
"transaction_date_datetime": txn["transaction_date_datetime"].isoformat(),
|
|
"post_date_timestamp": txn["post_date_timestamp"],
|
|
"post_date_datetime": txn["post_date_datetime"].isoformat(),
|
|
"transaction_description": txn["transaction_description"],
|
|
}
|
|
for txn in transactions
|
|
]
|
|
|
|
with output_file.open("w", encoding="utf-8") as f:
|
|
json.dump(serializable, f, indent=2)
|
|
|
|
print(f"Saved {len(transactions)} processed transaction(s) to {output_file}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|