From b7774487704d74d158df2c6af6464489954b7469 Mon Sep 17 00:00:00 2001 From: Code0987 Date: Wed, 29 Sep 2021 08:53:08 +0530 Subject: [PATCH] Include ms in `transaction_dt` (#7) --- CHANGELOG.md | 8 ++++++++ README.md | 2 +- card_data_parsers/parsers/happay_parser.py | 2 +- card_data_parsers/utils.py | 2 +- setup.py | 2 +- tests/card_data_parsers/amex/p1/expected.json | 4 ++-- tests/card_data_parsers/cdf/p2/expected.json | 8 ++++---- tests/card_data_parsers/cdf/p3/expected.json | 6 +++--- tests/card_data_parsers/happay/p1/expected.json | 12 ++++++------ tests/card_data_parsers/s3df/p1/expected.json | 14 +++++++------- tests/card_data_parsers/vcf/p1/expected.json | 4 ++-- 11 files changed, 36 insertions(+), 28 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..0aad21c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,8 @@ +# Change Log + +## [0.3.0] + +### Changed + +- Changed `transaction_dt` to include milliseconds. Updated function `get_iso_date_string`. + - Affects `external_id` diff --git a/README.md b/README.md index 4ed8075..9f242ff 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ git push origin v0.1.0 The parse method is supposed to return a list of transactions. This is a list of python dict objects that looks like this: ``` -[{"bank_name": "Test BANK", "vendor": "Test", "sync_type": "BANK FEED - VCF", "transaction_type": "debit", "currency": "EUR", "amount": "124.74", "transaction_date": "2018-11-30T10:00:00Z", "account_number": "4142********6333", "transaction_dt": "2018-11-30T10:00:00Z", "external_id": "b2a242d1d9814394b594044b77f36f2f"}] +[{"bank_name": "Test BANK", "vendor": "Test", "sync_type": "BANK FEED - VCF", "transaction_type": "debit", "currency": "EUR", "amount": "124.74", "transaction_date": "2018-11-30T10:00:00.000000Z", "account_number": "4142********6333", "transaction_dt": "2018-11-30T10:00:00.000000Z", "external_id": "b2a242d1d9814394b594044b77f36f2f"}] ``` If there is any non-backward compatible change to this structure e.g. a key is deleted, then bump up major number. Otherwise, bump up minor number. diff --git a/card_data_parsers/parsers/happay_parser.py b/card_data_parsers/parsers/happay_parser.py index eb6f747..c9d2390 100644 --- a/card_data_parsers/parsers/happay_parser.py +++ b/card_data_parsers/parsers/happay_parser.py @@ -65,7 +65,7 @@ def __get_transaction_from_line(trxn_line_orig, account_number_mask_begin, accou # transaction date txn.transaction_dt = datetime.datetime.strptime(txn.transaction_dt.strip(), "%Y-%m-%d") - txn.transaction_dt = txn.transaction_dt.strftime("%Y-%m-%dT%H:%M:%SZ") + txn.transaction_dt = txn.transaction_dt.strftime("%Y-%m-%dT%H:%M:%S.%fZ") # orig amount and orig currency if txn.foreign_amount and txn.foreign_currency: diff --git a/card_data_parsers/utils.py b/card_data_parsers/utils.py index 2d36fb4..b2c5813 100644 --- a/card_data_parsers/utils.py +++ b/card_data_parsers/utils.py @@ -80,7 +80,7 @@ def get_iso_date_string(date_string, date_format): iso_date_string = datetime.strptime(date_string.strip(), date_format) # hack for timezones: set time to 10 o clock iso_date_string = iso_date_string.replace(hour=10) - iso_date_string = iso_date_string.strftime("%Y-%m-%dT%H:%M:%SZ") + iso_date_string = iso_date_string.strftime("%Y-%m-%dT%H:%M:%S.%fZ") else: iso_date_string = None diff --git a/setup.py b/setup.py index b109b56..2d39d3e 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup( name='card_data_parsers', - version='0.2.0', + version='0.3.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 0dc5a44..ef78e2b 100644 --- a/tests/card_data_parsers/amex/p1/expected.json +++ b/tests/card_data_parsers/amex/p1/expected.json @@ -6,10 +6,10 @@ "currency": "CAD", "foreign_amount": "48.33", "foreign_currency": "USD", - "transaction_dt": "2009-03-13T10:00:00Z", + "transaction_dt": "2009-03-13T10:00:00.000000Z", "transaction_type": "debit", "description": "ABC-DEF 9511 HXLGGHWZOV M ZA", - "external_id": "dd11f01234dde3c25b1a4d87a764201e", + "external_id": "0d3eaafa0c8f934f362c53bb2d3ccd67", "merchant_category_code": "10", "vendor": "5", "bank_name": "Test Bank" diff --git a/tests/card_data_parsers/cdf/p2/expected.json b/tests/card_data_parsers/cdf/p2/expected.json index 6a6792f..b1216d4 100644 --- a/tests/card_data_parsers/cdf/p2/expected.json +++ b/tests/card_data_parsers/cdf/p2/expected.json @@ -1,7 +1,7 @@ [ { "account_number": "1234*********1213", - "transaction_dt": "2018-12-18T10:00:00Z", + "transaction_dt": "2018-12-18T10:00:00.000000Z", "transaction_type": "debit", "amount": "13.99", "currency": "EUR", @@ -10,7 +10,7 @@ }, { "account_number": "1234*********1213", - "transaction_dt": "2018-12-19T10:00:00Z", + "transaction_dt": "2018-12-19T10:00:00.000000Z", "transaction_type": "debit", "amount": "130", "currency": "EUR", @@ -19,7 +19,7 @@ }, { "account_number": "1234*********1213", - "transaction_dt": "2018-12-19T10:00:00Z", + "transaction_dt": "2018-12-19T10:00:00.000000Z", "transaction_type": "debit", "amount": "38.63", "currency": "EUR", @@ -28,7 +28,7 @@ }, { "account_number": "1234*********1213", - "transaction_dt": "2018-12-19T10:00:00Z", + "transaction_dt": "2018-12-19T10:00:00.000000Z", "transaction_type": "debit", "amount": "129", "currency": "EUR", diff --git a/tests/card_data_parsers/cdf/p3/expected.json b/tests/card_data_parsers/cdf/p3/expected.json index 0d7210c..a04df60 100644 --- a/tests/card_data_parsers/cdf/p3/expected.json +++ b/tests/card_data_parsers/cdf/p3/expected.json @@ -1,7 +1,7 @@ [ { "account_number": "1234*********1213", - "transaction_dt": "2018-12-18T10:00:00Z", + "transaction_dt": "2018-12-18T10:00:00.000000Z", "transaction_type": "debit", "amount": "5", "currency": "EUR", @@ -10,7 +10,7 @@ }, { "account_number": "1234*********1213", - "transaction_dt": "2018-12-18T10:00:00Z", + "transaction_dt": "2018-12-18T10:00:00.000000Z", "transaction_type": "debit", "amount": "3.89", "currency": "EUR", @@ -19,7 +19,7 @@ }, { "account_number": "1234*********1213", - "transaction_dt": "2018-12-18T10:00:00Z", + "transaction_dt": "2018-12-18T10:00:00.000000Z", "transaction_type": "debit", "amount": "89", "currency": "EUR", diff --git a/tests/card_data_parsers/happay/p1/expected.json b/tests/card_data_parsers/happay/p1/expected.json index a8dc9d0..ca4d7f6 100644 --- a/tests/card_data_parsers/happay/p1/expected.json +++ b/tests/card_data_parsers/happay/p1/expected.json @@ -1,12 +1,12 @@ [ { - "transaction_dt": "2021-08-13T00:00:00Z", + "transaction_dt": "2021-08-13T00:00:00.000000Z", "account_number": "**0123", "vendor": "RandomVendor1", "amount": 624.0, "transaction_type": "debit", "description": "", - "external_id": "22ad6bf6230053b0fdd4a17717615004", + "external_id": "60daa9e0ec4a6020f1e0c8f6e9b7b32b", "nickname": "Boi1", "currency": "INR", "foreign_amount": 624.0, @@ -14,13 +14,13 @@ "bank_name": "Test Bank" }, { - "transaction_dt": "2021-08-12T00:00:00Z", + "transaction_dt": "2021-08-12T00:00:00.000000Z", "account_number": "**0123", "vendor": "RandomVendor2", "amount": 1005.0, "transaction_type": "debit", "description": "", - "external_id": "3bb23c91900be9c326f7b80575250831", + "external_id": "30386309fbdaa313e31cde98fcc261c2", "nickname": "Boi2", "currency": "INR", "foreign_amount": 1005.0, @@ -28,13 +28,13 @@ "bank_name": "Test Bank" }, { - "transaction_dt": "2021-08-12T00:00:00Z", + "transaction_dt": "2021-08-12T00:00:00.000000Z", "account_number": "**0124", "vendor": "RandomVendor3", "amount": 114431.81, "transaction_type": "debit", "description": "", - "external_id": "910efbef3c4ab927fd4d8a2cd87ab664", + "external_id": "55e4b13075a195ea9c8bdeea59025e9f", "nickname": "Boi3", "currency": "INR", "foreign_amount": 1516.08, diff --git a/tests/card_data_parsers/s3df/p1/expected.json b/tests/card_data_parsers/s3df/p1/expected.json index 0243fa8..fe8f283 100644 --- a/tests/card_data_parsers/s3df/p1/expected.json +++ b/tests/card_data_parsers/s3df/p1/expected.json @@ -1,7 +1,7 @@ [ { "account_number": "2344******7566", - "transaction_dt": "2019-01-01T10:00:00Z", + "transaction_dt": "2019-01-01T10:00:00.000000Z", "transaction_type": "debit", "amount": "294.97", "currency": "GBP", @@ -10,7 +10,7 @@ }, { "account_number": "2344******7566", - "transaction_dt": "2019-01-01T10:00:00Z", + "transaction_dt": "2019-01-01T10:00:00.000000Z", "transaction_type": "debit", "amount": "109", "currency": "GBP", @@ -19,7 +19,7 @@ }, { "account_number": "2344******7567", - "transaction_dt": "2019-01-01T10:00:00Z", + "transaction_dt": "2019-01-01T10:00:00.000000Z", "transaction_type": "debit", "amount": "2098.8", "currency": "GBP", @@ -28,7 +28,7 @@ }, { "account_number": "2344******7567", - "transaction_dt": "2019-01-01T10:00:00Z", + "transaction_dt": "2019-01-01T10:00:00.000000Z", "transaction_type": "debit", "amount": "5.64", "currency": "GBP", @@ -37,7 +37,7 @@ }, { "account_number": "2344******7567", - "transaction_dt": "2019-01-01T10:00:00Z", + "transaction_dt": "2019-01-01T10:00:00.000000Z", "transaction_type": "debit", "amount": "205.16", "currency": "GBP", @@ -48,7 +48,7 @@ }, { "account_number": "2344******7567", - "transaction_dt": "2019-01-01T10:00:00Z", + "transaction_dt": "2019-01-01T10:00:00.000000Z", "transaction_type": "debit", "amount": "74", "currency": "GBP", @@ -57,7 +57,7 @@ }, { "account_number": "2344******7567", - "transaction_dt": "2019-01-01T10:00:00Z", + "transaction_dt": "2019-01-01T10:00:00.000000Z", "transaction_type": "debit", "amount": "74", "currency": "GBP", diff --git a/tests/card_data_parsers/vcf/p1/expected.json b/tests/card_data_parsers/vcf/p1/expected.json index d3a0955..611ba56 100644 --- a/tests/card_data_parsers/vcf/p1/expected.json +++ b/tests/card_data_parsers/vcf/p1/expected.json @@ -5,8 +5,8 @@ "amount": "89.98", "currency": "EUR", "transaction_type": "debit", - "transaction_dt": "2019-01-02T10:00:00Z", - "external_id": "521bb8c41273282f9d5e46b9de1fbc01", + "transaction_dt": "2019-01-02T10:00:00.000000Z", + "external_id": "21f3c22b19f44df7536cf16ba1040ecd", "merchant_category_code": "5044", "sequence_number": "0032044068", "bank_name": "Test Bank"