Pulls in Shipping Costs and adds them to column D in the report file.

This commit is contained in:
Dan Dembinski
2019-06-20 16:35:20 -04:00
parent ffd1cebdaf
commit 4d97c8aeb7

74
main.py
View File

@@ -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 = """<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
@@ -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 = """ <filterNameOrXml>&lt;?xml version="1.0"?&gt; &lt;PFWebFilter:UserFilter xmlns:PFWebFilter="http://www.pageflex.com/schemas/2004/Storefront/UserFilters/20040817" filterClass="Orders"&gt; &lt;PFWebFilter:Step publicFieldName="Balance Due" query="ExactUnequals" minValue="0.00" maxValue="" /&gt; &lt;PFWebFilter:Step publicFieldName="Order Status" query="ExactEquals" minValue="Completed" maxValue="" /&gt; &lt;/PFWebFilter:UserFilter&gt;</filterNameOrXml>
"""
@@ -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('</GetReportResult>')
temp2 = temp1[1].split('<error />')
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 = """<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<FindOrderID xmlns="http://www.pageflex.com/XmlWebServices/2004/StorefrontAPI/20041111">
<token>""" + ticket + """</token>
<externalid>"""+x+"""</externalid>
</FindOrderID>
</soap12:Body>
</soap12:Envelope>"""
# 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 = """<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<GetValue xmlns="http://www.pageflex.com/XmlWebServices/2004/StorefrontAPI/20041111">
<t>"""+ticket+"""</t>
<fname>ShippingCharge</fname>
<ftype>OrderProperty</ftype>
<objid>"""+z+"""</objid>
</GetValue>
</soap12:Body>
</soap12:Envelope>
"""
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():