Pulls in Shipping Costs and adds them to column D in the report file.
This commit is contained in:
74
main.py
74
main.py
@@ -4,6 +4,8 @@ from bs4 import BeautifulSoup as bs
|
|||||||
from openpyxl import workbook
|
from openpyxl import workbook
|
||||||
from openpyxl.styles import Font
|
from openpyxl.styles import Font
|
||||||
|
|
||||||
|
bold = Font(bold=True)
|
||||||
|
|
||||||
def Obtain_Ticket(URL, HOST):
|
def Obtain_Ticket(URL, HOST):
|
||||||
GetTicket = """<?xml version="1.0" encoding="utf-8"?>
|
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">
|
<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):
|
def Run_Report(ticket, URL, HOST, REPORT_FIELDS, ws, wb):
|
||||||
|
|
||||||
|
ExternalID = []
|
||||||
|
id = []
|
||||||
|
shippingcost = []
|
||||||
|
|
||||||
report_filter = """ <filterNameOrXml><?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></filterNameOrXml>
|
report_filter = """ <filterNameOrXml><?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></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'}
|
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
|
response = requests.post(url=URL, data=send, headers=headers).text
|
||||||
# print(response)
|
|
||||||
temp1 = response.split('</GetReportResult>')
|
temp1 = response.split('</GetReportResult>')
|
||||||
temp2 = temp1[1].split('<error />')
|
temp2 = temp1[1].split('<error />')
|
||||||
report = (temp2[0])
|
report = (temp2[0])
|
||||||
@@ -77,15 +82,72 @@ def Run_Report(ticket, URL, HOST, REPORT_FIELDS, ws, wb):
|
|||||||
ws.append(results)
|
ws.append(results)
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
test = []
|
# Grabs all the Order IDs from Column A
|
||||||
for cell in ws['A']:
|
for cell in ws['A']:
|
||||||
test.append(cell.value)
|
ExternalID.append(cell.value)
|
||||||
test.pop(0)
|
ExternalID.pop(0)
|
||||||
print(test)
|
|
||||||
|
|
||||||
|
# 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():
|
def loadMenu():
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user