From 4d97c8aeb73bd583e78e8c1ed3c29791c7f98d66 Mon Sep 17 00:00:00 2001 From: Dan Dembinski Date: Thu, 20 Jun 2019 16:35:20 -0400 Subject: [PATCH] Pulls in Shipping Costs and adds them to column D in the report file. --- main.py | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 68 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 151c350..2d609c8 100644 --- a/main.py +++ b/main.py @@ -4,6 +4,8 @@ from bs4 import BeautifulSoup as bs from openpyxl import workbook from openpyxl.styles import Font +bold = Font(bold=True) + def Obtain_Ticket(URL, HOST): GetTicket = """ @@ -40,6 +42,10 @@ def Release_Ticket(ticket, URL, HOST): def Run_Report(ticket, URL, HOST, REPORT_FIELDS, ws, wb): + ExternalID = [] + id = [] + shippingcost = [] + report_filter = """ <?xml version="1.0"?> <PFWebFilter:UserFilter xmlns:PFWebFilter="http://www.pageflex.com/schemas/2004/Storefront/UserFilters/20040817" filterClass="Orders"> <PFWebFilter:Step publicFieldName="Balance Due" query="ExactUnequals" minValue="0.00" maxValue="" /> <PFWebFilter:Step publicFieldName="Order Status" query="ExactEquals" minValue="Completed" maxValue="" /> </PFWebFilter:UserFilter> """ @@ -61,7 +67,6 @@ def Run_Report(ticket, URL, HOST, REPORT_FIELDS, ws, wb): headers = {'Host': HOST, 'Content-Type': 'application/soap+xml; charset=utf-8', 'Content-Length': 'length', 'SOAPAction': 'http://www.pageflex.com/XmlWebServices/2004/StorefrontAPI/20041111/GetReport'} response = requests.post(url=URL, data=send, headers=headers).text - # print(response) temp1 = response.split('') temp2 = temp1[1].split('') report = (temp2[0]) @@ -77,15 +82,72 @@ def Run_Report(ticket, URL, HOST, REPORT_FIELDS, ws, wb): ws.append(results) results = [] - test = [] +# Grabs all the Order IDs from Column A for cell in ws['A']: - test.append(cell.value) - test.pop(0) - print(test) + ExternalID.append(cell.value) + ExternalID.pop(0) +# Reset the header SOAPAction to FindOrderID. This is needed to get the OrderID needed for Shipping Charges + headers = {'Host': HOST, 'Content-Type': 'application/soap+xml; charset=utf-8', 'Content-Length': 'length', 'SOAPAction': 'http://www.pageflex.com/XmlWebServices/2004/StorefrontAPI/20041111/FindOrderID'} +# Loop through ExternalIDs + print("Getting Doc IDs") + for x in ExternalID: + ID_send = """ + + + + """ + ticket + """ + """+x+""" + + + """ - # wb.save('report.xlsx') +# Parse returned for DocIDs + getDocID = requests.post(url=URL, data=ID_send, headers=headers).text + + y = bs(getDocID, "lxml") + + for w in y.find_all('val'): + id.append(w.text) +# Reset headers for GerValue + headers = {'Host': HOST, 'Content-Type': 'application/soap+xml; charset=utf-8', 'Content-Length': 'length','SOAPAction': 'http://www.pageflex.com/XmlWebServices/2004/StorefrontAPI/20041111/GetValue'} + print("Getting Shipping Costs") +# Loop through the ExternalIDs and get the Shipping Charge + for z in id: + shipping_send = """ + + + + """+ticket+""" + ShippingCharge + OrderProperty + """+z+""" + + + + """ + + getShipping = requests.post(url=URL, data=shipping_send, headers=headers).text + + y = bs(getShipping, "lxml") + for w in y.find_all('fval'): + shippingcost.append(float(w.text)) + print(shippingcost) + +# Add Shipping Charge column. Set header and make bold + ws.insert_cols(4) + ws['D1'] = "Shipping Charges" + ws['D1'].font = bold + +# Load Shipping Charges into the sheet + count = 2 + for x in shippingcost: + ws.cell(column=4, row=count, value=x) + count = count + 1 + wb.save('report.xlsx') def loadMenu():