From ab8b8e37ebee106dea4a84f6a97f61e1e917c20a Mon Sep 17 00:00:00 2001 From: Kulsekar4 Date: Sun, 6 Feb 2022 21:49:21 +0530 Subject: [PATCH] FYLE-1xqdn4y: Extracting post date from bank feeds --- CHANGELOG.md | 6 ++++++ card_data_parsers/models/transaction.py | 1 + card_data_parsers/parsers/amex_parser.py | 1 + card_data_parsers/parsers/cdf_parser.py | 6 ++++++ card_data_parsers/parsers/s3df_parser.py | 6 ++++++ card_data_parsers/parsers/vcf_parser.py | 4 ++++ setup.py | 2 +- tests/card_data_parsers/amex/p1/expected.json | 1 + tests/card_data_parsers/amex/p2/expected.json | 1 + tests/card_data_parsers/cdf/p2/expected.json | 12 +++++++---- tests/card_data_parsers/cdf/p3/expected.json | 9 +++++--- tests/card_data_parsers/cdf/p4/expected.json | 9 +++++--- tests/card_data_parsers/s3df/p1/expected.json | 21 ++++++++++++------- tests/card_data_parsers/s3df/p2/expected.json | 21 ++++++++++++------- tests/card_data_parsers/vcf/p1/expected.json | 3 ++- tests/card_data_parsers/vcf/p2/expected.json | 3 ++- tests/card_data_parsers/vcf/p3/expected.json | 3 ++- 17 files changed, 81 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64bd2e7..7d99a62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change Log +## [0.8.0] + +### Changed + +- Fetching the `post_date` from amex, cdf, s3df and vcf parsers. + ## [0.7.0] ### Changed diff --git a/card_data_parsers/models/transaction.py b/card_data_parsers/models/transaction.py index 59fee7a..fcec672 100644 --- a/card_data_parsers/models/transaction.py +++ b/card_data_parsers/models/transaction.py @@ -39,3 +39,4 @@ class Transaction: description: str = None external_id: str = None bank_name: str = None + post_date: str = None diff --git a/card_data_parsers/parsers/amex_parser.py b/card_data_parsers/parsers/amex_parser.py index 162f617..2ac2b67 100644 --- a/card_data_parsers/parsers/amex_parser.py +++ b/card_data_parsers/parsers/amex_parser.py @@ -65,6 +65,7 @@ def __extract_transaction_fields(txn_line, default_values): txn.transaction_type = txn_line[736:737].strip() txn.description = txn_line[946:991].strip() txn.external_id = txn_line[631:681].strip() + txn.post_date = get_iso_date_string(txn_line[573:581].strip(), "%Y%m%d") txn.decimal_place_indicator = txn_line[768:769].strip() txn.merchant_category_code = txn_line[1678:1681].strip() diff --git a/card_data_parsers/parsers/cdf_parser.py b/card_data_parsers/parsers/cdf_parser.py index f793f68..b57f396 100644 --- a/card_data_parsers/parsers/cdf_parser.py +++ b/card_data_parsers/parsers/cdf_parser.py @@ -60,6 +60,12 @@ def __extract_transaction_fields(root: ElementTree, account_number, nickname, de txn.transaction_dt = get_iso_date_string( txn.transaction_dt.strip(), '%Y-%m-%d') + # Post Date + txn.post_date = CDFParser.__get_element_by_tag( + ftrxn, 'PostingDate').text + txn.post_date = get_iso_date_string( + txn.post_date.strip(), '%Y-%m-%d') + # Transaction Type txn.transaction_type = CDFParser.__get_element_by_tag( ftrxn, 'DebitOrCreditIndicator').text diff --git a/card_data_parsers/parsers/s3df_parser.py b/card_data_parsers/parsers/s3df_parser.py index 3e6816e..fd24c0e 100644 --- a/card_data_parsers/parsers/s3df_parser.py +++ b/card_data_parsers/parsers/s3df_parser.py @@ -60,6 +60,12 @@ def __extract_transaction_fields(root, account_number, default_values): txn.transaction_dt = get_iso_date_string( txn.transaction_dt.strip(), '%Y-%m-%d') + # Post Date + txn.post_date = S3DFParser.__get_element_by_tag( + ftrxn, 'PostingDate').text + txn.post_date = get_iso_date_string( + txn.post_date.strip(), '%Y-%m-%d') + # Transaction Type txn.transaction_type = S3DFParser.__get_element_by_tag( ftrxn, 'DebitOrCreditIndicator').text diff --git a/card_data_parsers/parsers/vcf_parser.py b/card_data_parsers/parsers/vcf_parser.py index 924a073..82866e3 100644 --- a/card_data_parsers/parsers/vcf_parser.py +++ b/card_data_parsers/parsers/vcf_parser.py @@ -71,6 +71,9 @@ def __process_transaction(txn, account_number_mask_begin, account_number_mask_en txn.transaction_dt = get_iso_date_string( txn.transaction_dt.strip(), '%m%d%Y') + txn.post_date = get_iso_date_string( + txn.post_date.strip(), '%m%d%Y') + card_num = txn.account_number # Masking the card number if account_number_mask_begin is not None and account_number_mask_end is not None: @@ -121,6 +124,7 @@ def __extract_transaction_fields(transaction, default_values): txn.external_id = transaction[3].strip() txn.merchant_category_code = transaction[16].strip() txn.sequence_number = transaction[4].strip() + txn.post_date = transaction[2].strip() # other amounts to consider are # at positions 20, 28, 29 diff --git a/setup.py b/setup.py index 611c45e..d2a4f93 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup( name='card_data_parsers', - version='0.7.0', + version='0.8.0', author='Siva Narayanan', author_email='siva@fyle.in', url='https://www.fylehq.com', diff --git a/tests/card_data_parsers/amex/p1/expected.json b/tests/card_data_parsers/amex/p1/expected.json index 0077075..aabfac1 100644 --- a/tests/card_data_parsers/amex/p1/expected.json +++ b/tests/card_data_parsers/amex/p1/expected.json @@ -13,6 +13,7 @@ "merchant_category_code": "10", "vendor": "5", "bank_name": "Test Bank", + "post_date": "2009-05-26T10:00:00.000000Z", "transaction_id": "0914600172007637906017110005010001521" } ] \ No newline at end of file diff --git a/tests/card_data_parsers/amex/p2/expected.json b/tests/card_data_parsers/amex/p2/expected.json index f867aee..60e9090 100644 --- a/tests/card_data_parsers/amex/p2/expected.json +++ b/tests/card_data_parsers/amex/p2/expected.json @@ -13,6 +13,7 @@ "merchant_category_code": "10", "vendor": "5", "bank_name": "Test Bank", + "post_date": "2009-05-26T10:00:00.000000Z", "transaction_id": "0914600172007637906017110005010001521" } ] \ No newline at end of file diff --git a/tests/card_data_parsers/cdf/p2/expected.json b/tests/card_data_parsers/cdf/p2/expected.json index b1216d4..7194f0a 100644 --- a/tests/card_data_parsers/cdf/p2/expected.json +++ b/tests/card_data_parsers/cdf/p2/expected.json @@ -6,7 +6,8 @@ "amount": "13.99", "currency": "EUR", "vendor": "ABCDEF", - "external_id": "bcc54fff373cf5b4eb1b3b8c53c111bf" + "external_id": "bcc54fff373cf5b4eb1b3b8c53c111bf", + "post_date": "2018-12-20T10:00:00.000000Z" }, { "account_number": "1234*********1213", @@ -15,7 +16,8 @@ "amount": "130", "currency": "EUR", "vendor": "ABCDEF", - "external_id": "c36c9ba0602a898336e1c08360495d5d" + "external_id": "c36c9ba0602a898336e1c08360495d5d", + "post_date": "2018-12-20T10:00:00.000000Z" }, { "account_number": "1234*********1213", @@ -24,7 +26,8 @@ "amount": "38.63", "currency": "EUR", "vendor": "ABCDEF", - "external_id": "379e9c62e0804eeb9ff0864fb03b96f0" + "external_id": "379e9c62e0804eeb9ff0864fb03b96f0", + "post_date": "2018-12-20T10:00:00.000000Z" }, { "account_number": "1234*********1213", @@ -33,6 +36,7 @@ "amount": "129", "currency": "EUR", "vendor": "ABCDEF", - "external_id": "14a181d358d82b3dd3532e5ec47653d8" + "external_id": "14a181d358d82b3dd3532e5ec47653d8", + "post_date": "2018-12-20T10:00:00.000000Z" } ] \ No newline at end of file diff --git a/tests/card_data_parsers/cdf/p3/expected.json b/tests/card_data_parsers/cdf/p3/expected.json index a04df60..a4c6696 100644 --- a/tests/card_data_parsers/cdf/p3/expected.json +++ b/tests/card_data_parsers/cdf/p3/expected.json @@ -6,7 +6,8 @@ "amount": "5", "currency": "EUR", "vendor": "Abcd", - "external_id": "516f72d0902bafeec0448b23a9735b94" + "external_id": "516f72d0902bafeec0448b23a9735b94", + "post_date": "2018-12-19T10:00:00.000000Z" }, { "account_number": "1234*********1213", @@ -15,7 +16,8 @@ "amount": "3.89", "currency": "EUR", "vendor": "Abcd", - "external_id": "7479ca62690d075b08a39e072df79c2a" + "external_id": "7479ca62690d075b08a39e072df79c2a", + "post_date": "2018-12-19T10:00:00.000000Z" }, { "account_number": "1234*********1213", @@ -24,6 +26,7 @@ "amount": "89", "currency": "EUR", "vendor": "Abcdedfgh", - "external_id": "79c952ed6c2e4fb3038a405dc494cade" + "external_id": "79c952ed6c2e4fb3038a405dc494cade", + "post_date": "2018-12-19T10:00:00.000000Z" } ] \ No newline at end of file diff --git a/tests/card_data_parsers/cdf/p4/expected.json b/tests/card_data_parsers/cdf/p4/expected.json index a7e9b86..ff8245d 100644 --- a/tests/card_data_parsers/cdf/p4/expected.json +++ b/tests/card_data_parsers/cdf/p4/expected.json @@ -6,7 +6,8 @@ "amount": "5", "currency": "EUR", "vendor": "Abcd", - "external_id": "516f72d0902bafeec0448b23a9735b94" + "external_id": "516f72d0902bafeec0448b23a9735b94", + "post_date": "2018-12-19T10:00:00.000000Z" }, { "account_number": "12345678910111213", @@ -15,7 +16,8 @@ "amount": "3.89", "currency": "EUR", "vendor": "Abcd", - "external_id": "7479ca62690d075b08a39e072df79c2a" + "external_id": "7479ca62690d075b08a39e072df79c2a", + "post_date": "2018-12-19T10:00:00.000000Z" }, { "account_number": "12345678910111213", @@ -24,6 +26,7 @@ "amount": "89", "currency": "EUR", "vendor": "Abcdedfgh", - "external_id": "79c952ed6c2e4fb3038a405dc494cade" + "external_id": "79c952ed6c2e4fb3038a405dc494cade", + "post_date": "2018-12-19T10:00:00.000000Z" } ] \ No newline at end of file diff --git a/tests/card_data_parsers/s3df/p1/expected.json b/tests/card_data_parsers/s3df/p1/expected.json index fe8f283..fcbb7de 100644 --- a/tests/card_data_parsers/s3df/p1/expected.json +++ b/tests/card_data_parsers/s3df/p1/expected.json @@ -6,7 +6,8 @@ "amount": "294.97", "currency": "GBP", "vendor": "Abcd, --", - "external_id": "5e65fcc2d8388da145d00043ce50dff9" + "external_id": "5e65fcc2d8388da145d00043ce50dff9", + "post_date": "2019-10-02T10:00:00.000000Z" }, { "account_number": "2344******7566", @@ -15,7 +16,8 @@ "amount": "109", "currency": "GBP", "vendor": "Abcd, --", - "external_id": "739a85df06f04d7c823c3a9012cf05e3" + "external_id": "739a85df06f04d7c823c3a9012cf05e3", + "post_date": "2019-10-02T10:00:00.000000Z" }, { "account_number": "2344******7567", @@ -24,7 +26,8 @@ "amount": "2098.8", "currency": "GBP", "vendor": "PARK PLAZA LONDON WATE, --", - "external_id": "bdafcb93370618638a43b53cc5880a28" + "external_id": "bdafcb93370618638a43b53cc5880a28", + "post_date": "2019-10-02T10:00:00.000000Z" }, { "account_number": "2344******7567", @@ -33,7 +36,8 @@ "amount": "5.64", "currency": "GBP", "vendor": "Abcd, --", - "external_id": "1a9375ab8269860d6ee2c1c758f4694d" + "external_id": "1a9375ab8269860d6ee2c1c758f4694d", + "post_date": "2019-10-02T10:00:00.000000Z" }, { "account_number": "2344******7567", @@ -44,7 +48,8 @@ "foreign_amount": "230.4", "foreign_currency": "EUR", "vendor": "Abcd, --", - "external_id": "0205ba3ba7e22335177c2bb52e1bf68f" + "external_id": "0205ba3ba7e22335177c2bb52e1bf68f", + "post_date": "2019-10-02T10:00:00.000000Z" }, { "account_number": "2344******7567", @@ -53,7 +58,8 @@ "amount": "74", "currency": "GBP", "vendor": "Abcd, --", - "external_id": "d331fbcc2d265d4d016b4f6ce76c66b9" + "external_id": "d331fbcc2d265d4d016b4f6ce76c66b9", + "post_date": "2019-10-02T10:00:00.000000Z" }, { "account_number": "2344******7567", @@ -62,6 +68,7 @@ "amount": "74", "currency": "GBP", "vendor": "Abcd, --", - "external_id": "9cf17c980e286b7f88b775d5bb343b18" + "external_id": "9cf17c980e286b7f88b775d5bb343b18", + "post_date": "2019-10-02T10:00:00.000000Z" } ] \ No newline at end of file diff --git a/tests/card_data_parsers/s3df/p2/expected.json b/tests/card_data_parsers/s3df/p2/expected.json index ef00c36..3102cbe 100644 --- a/tests/card_data_parsers/s3df/p2/expected.json +++ b/tests/card_data_parsers/s3df/p2/expected.json @@ -6,7 +6,8 @@ "amount": "294.97", "currency": "GBP", "vendor": "Abcd, --", - "external_id": "5e65fcc2d8388da145d00043ce50dff9" + "external_id": "5e65fcc2d8388da145d00043ce50dff9", + "post_date": "2019-10-02T10:00:00.000000Z" }, { "account_number": "23445345667566", @@ -15,7 +16,8 @@ "amount": "109", "currency": "GBP", "vendor": "Abcd, --", - "external_id": "739a85df06f04d7c823c3a9012cf05e3" + "external_id": "739a85df06f04d7c823c3a9012cf05e3", + "post_date": "2019-10-02T10:00:00.000000Z" }, { "account_number": "23445345667567", @@ -24,7 +26,8 @@ "amount": "2098.8", "currency": "GBP", "vendor": "PARK PLAZA LONDON WATE, --", - "external_id": "bdafcb93370618638a43b53cc5880a28" + "external_id": "bdafcb93370618638a43b53cc5880a28", + "post_date": "2019-10-02T10:00:00.000000Z" }, { "account_number": "23445345667567", @@ -33,7 +36,8 @@ "amount": "5.64", "currency": "GBP", "vendor": "Abcd, --", - "external_id": "1a9375ab8269860d6ee2c1c758f4694d" + "external_id": "1a9375ab8269860d6ee2c1c758f4694d", + "post_date": "2019-10-02T10:00:00.000000Z" }, { "account_number": "23445345667567", @@ -44,7 +48,8 @@ "foreign_amount": "230.4", "foreign_currency": "EUR", "vendor": "Abcd, --", - "external_id": "0205ba3ba7e22335177c2bb52e1bf68f" + "external_id": "0205ba3ba7e22335177c2bb52e1bf68f", + "post_date": "2019-10-02T10:00:00.000000Z" }, { "account_number": "23445345667567", @@ -53,7 +58,8 @@ "amount": "74", "currency": "GBP", "vendor": "Abcd, --", - "external_id": "d331fbcc2d265d4d016b4f6ce76c66b9" + "external_id": "d331fbcc2d265d4d016b4f6ce76c66b9", + "post_date": "2019-10-02T10:00:00.000000Z" }, { "account_number": "23445345667567", @@ -62,6 +68,7 @@ "amount": "74", "currency": "GBP", "vendor": "Abcd, --", - "external_id": "9cf17c980e286b7f88b775d5bb343b18" + "external_id": "9cf17c980e286b7f88b775d5bb343b18", + "post_date": "2019-10-02T10:00:00.000000Z" } ] \ No newline at end of file diff --git a/tests/card_data_parsers/vcf/p1/expected.json b/tests/card_data_parsers/vcf/p1/expected.json index 611ba56..a4ba5b7 100644 --- a/tests/card_data_parsers/vcf/p1/expected.json +++ b/tests/card_data_parsers/vcf/p1/expected.json @@ -9,6 +9,7 @@ "external_id": "21f3c22b19f44df7536cf16ba1040ecd", "merchant_category_code": "5044", "sequence_number": "0032044068", - "bank_name": "Test Bank" + "bank_name": "Test Bank", + "post_date": "2019-01-03T10:00:00.000000Z" } ] \ No newline at end of file diff --git a/tests/card_data_parsers/vcf/p2/expected.json b/tests/card_data_parsers/vcf/p2/expected.json index 1036e60..572d236 100644 --- a/tests/card_data_parsers/vcf/p2/expected.json +++ b/tests/card_data_parsers/vcf/p2/expected.json @@ -9,6 +9,7 @@ "external_id": "3d31ebfed8cb00c26db8403d5f744598", "bank_name": "Test Bank", "merchant_category_code": "", - "sequence_number": "0000009688" + "sequence_number": "0000009688", + "post_date": "2021-11-12T10:00:00.000000Z" } ] \ No newline at end of file diff --git a/tests/card_data_parsers/vcf/p3/expected.json b/tests/card_data_parsers/vcf/p3/expected.json index 47f4b8a..43e6188 100644 --- a/tests/card_data_parsers/vcf/p3/expected.json +++ b/tests/card_data_parsers/vcf/p3/expected.json @@ -9,6 +9,7 @@ "external_id": "a0b742b2bcd36a151c75cfaeadd4ba96", "bank_name": "Test Bank", "merchant_category_code": "", - "sequence_number": "0000009688" + "sequence_number": "0000009688", + "post_date": "2021-11-12T10:00:00.000000Z" } ] \ No newline at end of file