diff --git a/csv2ofx/mappings/amazon.py b/csv2ofx/mappings/amazon.py new file mode 100644 index 0000000..b4e5d7e --- /dev/null +++ b/csv2ofx/mappings/amazon.py @@ -0,0 +1,35 @@ +""" +Import transactions from Amazon Order History +as exported by Amazon Order History Reporter +(https://chrome.google.com/webstore/detail/amazon-order-history-repo/mgkilgclilajckgnedgjgnfdokkgnibi). +""" + +import os +import functools +from operator import itemgetter + + +@functools.lru_cache() +def cards(): + setting = os.environ.get('AMAZON_EXCLUDE_CARDS', None) + return setting.split(',') if setting else [] + + +def exclude_cards(row): + return not any(card in row['payments'] for card in cards()) + + +mapping = { + 'has_header': True, + 'delimiter': ',', + 'bank': 'Amazon Purchases', + 'account_id': os.environ.get('AMAZON_PURCHASES_ACCOUNT', '100000001'), + 'date': itemgetter('date'), + 'amount': itemgetter('total'), + 'payee': 'Amazon', + 'desc': itemgetter('items'), + 'id': itemgetter('order id'), + 'type': 'DEBIT', + 'last_row': -1, + 'filter': exclude_cards, +}