From 03ac7602830efa8d3d962308fc985f7f431bca48 Mon Sep 17 00:00:00 2001 From: Eduardo Araujo Date: Fri, 19 Sep 2025 12:22:31 -0500 Subject: [PATCH 1/3] Implemented build_terms_query and parse_and_print --- terms.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/terms.py b/terms.py index 574a9d6..28b0933 100644 --- a/terms.py +++ b/terms.py @@ -9,13 +9,34 @@ def build_terms_query() -> str: - """Return a minimal TermsQueryRq XML.""" - raise NotImplementedError() + """Return a minimal TermsQueryRq XML (only required fields).""" + return """ + + + + +""" def parse_and_print(response_xml: str) -> None: """Parse response and print term name + discount days.""" - raise NotImplementedError() + root = ET.fromstring(response_xml) + + # Get the statusCode and statusMessage from the response + msgs_response = root.find(".//QBXMLMsgsRs/TermsQueryRs") + if msgs_response is not None: + status_code = msgs_response.get("statusCode") + status_message = msgs_response.get("statusMessage") + + if status_code != "0": # Not successful + print(f"Error {status_code}: {status_message}") + return + + # Loop through all StandardTermsRet tags + for terms in root.findall(".//StandardTermsRet"): + name = terms.find("Name") + discount_days = terms.find("DiscountDays") + print(f"{name.text if name is not None else 'N/A'} - {discount_days.text if discount_days is not None else 'N/A'}") def main(): @@ -50,4 +71,4 @@ def main(): if __name__ == "__main__": - main() + main() \ No newline at end of file From 09fde3ee14a8900777d92259e53d615eac62e400 Mon Sep 17 00:00:00 2001 From: Parikshith-Saraswathi Date: Fri, 19 Sep 2025 21:13:15 +0000 Subject: [PATCH 2/3] Making few corrections --- response.xml | 56 ++++++++++++++++++++++++++-------------------------- terms.py | 12 ++++++----- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/response.xml b/response.xml index 3958409..a287785 100644 --- a/response.xml +++ b/response.xml @@ -3,10 +3,10 @@ -80000001-1758063532 -2025-09-16T22:58:52+00:00 -2025-09-16T22:58:52+00:00 -1758063532 +80000001-1758131687 +2025-09-17T17:54:47+00:00 +2025-09-17T17:54:47+00:00 +1758131687 1% 10 Net 30 true 30 @@ -14,10 +14,10 @@ 1.00 -80000002-1758063532 -2025-09-16T22:58:52+00:00 -2025-09-16T22:58:52+00:00 -1758063532 +80000002-1758131687 +2025-09-17T17:54:47+00:00 +2025-09-17T17:54:47+00:00 +1758131687 2% 10 Net 30 true 30 @@ -25,10 +25,10 @@ 2.00 -80000003-1758063532 -2025-09-16T22:58:52+00:00 -2025-09-16T22:58:52+00:00 -1758063532 +80000003-1758131687 +2025-09-17T17:54:47+00:00 +2025-09-17T17:54:47+00:00 +1758131687 Consignment true 90 @@ -36,10 +36,10 @@ 0.00 -80000004-1758063532 -2025-09-16T22:58:52+00:00 -2025-09-16T22:58:52+00:00 -1758063532 +80000004-1758131687 +2025-09-17T17:54:47+00:00 +2025-09-17T17:54:47+00:00 +1758131687 Due on receipt true 0 @@ -47,10 +47,10 @@ 0.00 -80000005-1758063532 -2025-09-16T22:58:52+00:00 -2025-09-16T22:58:52+00:00 -1758063532 +80000005-1758131687 +2025-09-17T17:54:47+00:00 +2025-09-17T17:54:47+00:00 +1758131687 Net 15 true 15 @@ -58,10 +58,10 @@ 0.00 -80000006-1758063532 -2025-09-16T22:58:52+00:00 -2025-09-16T22:58:52+00:00 -1758063532 +80000006-1758131687 +2025-09-17T17:54:47+00:00 +2025-09-17T17:54:47+00:00 +1758131687 Net 30 true 30 @@ -69,10 +69,10 @@ 0.00 -80000007-1758063532 -2025-09-16T22:58:52+00:00 -2025-09-16T22:58:52+00:00 -1758063532 +80000007-1758131687 +2025-09-17T17:54:47+00:00 +2025-09-17T17:54:47+00:00 +1758131687 Net 60 true 60 diff --git a/terms.py b/terms.py index 28b0933..6c2bca8 100644 --- a/terms.py +++ b/terms.py @@ -10,12 +10,14 @@ def build_terms_query() -> str: """Return a minimal TermsQueryRq XML (only required fields).""" - return """ + request_body = """ + - - - + + + """ + return request_body def parse_and_print(response_xml: str) -> None: @@ -36,7 +38,7 @@ def parse_and_print(response_xml: str) -> None: for terms in root.findall(".//StandardTermsRet"): name = terms.find("Name") discount_days = terms.find("DiscountDays") - print(f"{name.text if name is not None else 'N/A'} - {discount_days.text if discount_days is not None else 'N/A'}") + print(f"{name.text if name is not None else 'N/A'}") def main(): From 01abd485d5c0a81e4d78177a968985b76add1513 Mon Sep 17 00:00:00 2001 From: Parikshith-Saraswathi Date: Fri, 19 Sep 2025 21:22:17 +0000 Subject: [PATCH 3/3] Adding comment lines --- terms.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/terms.py b/terms.py index 6c2bca8..e192513 100644 --- a/terms.py +++ b/terms.py @@ -24,7 +24,7 @@ def parse_and_print(response_xml: str) -> None: """Parse response and print term name + discount days.""" root = ET.fromstring(response_xml) - # Get the statusCode and statusMessage from the response + # Get the statusCode and statusMessage from the response. msgs_response = root.find(".//QBXMLMsgsRs/TermsQueryRs") if msgs_response is not None: status_code = msgs_response.get("statusCode") @@ -34,7 +34,7 @@ def parse_and_print(response_xml: str) -> None: print(f"Error {status_code}: {status_message}") return - # Loop through all StandardTermsRet tags + # Loop through all StandardTermsRet tags. for terms in root.findall(".//StandardTermsRet"): name = terms.find("Name") discount_days = terms.find("DiscountDays")