Broke report appending into a separate function/file. Started working on Column Format Checking Function
This commit is contained in:
31
WriteReport.py
Normal file
31
WriteReport.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
def Write_Report(y, ws, columnFormat, SSheader):
|
||||||
|
results = []
|
||||||
|
|
||||||
|
count = 0
|
||||||
|
for child in y.report:
|
||||||
|
for childs in child:
|
||||||
|
print(columnFormat[SSheader[count]])
|
||||||
|
count = count + 1
|
||||||
|
if '$' in childs.text:
|
||||||
|
convert = childs.text
|
||||||
|
apply = convert[1:]
|
||||||
|
results.append(float(apply.replace(',', '')))
|
||||||
|
else:
|
||||||
|
results.append(childs.text)
|
||||||
|
ws.append(results)
|
||||||
|
results = []
|
||||||
|
count = 0
|
||||||
|
|
||||||
|
def Detail_Write_Report(y, ws):
|
||||||
|
results = []
|
||||||
|
|
||||||
|
for child in y.report:
|
||||||
|
for childs in child:
|
||||||
|
if '$' in childs.text:
|
||||||
|
convert = childs.text
|
||||||
|
apply = convert[1:]
|
||||||
|
results.append(float(apply.replace(',', '')))
|
||||||
|
else:
|
||||||
|
results.append(childs.text)
|
||||||
|
ws.append(results)
|
||||||
|
results = []
|
||||||
@@ -2,11 +2,82 @@ from bs4 import BeautifulSoup as bs
|
|||||||
# import csv
|
# import csv
|
||||||
from openpyxl import workbook
|
from openpyxl import workbook
|
||||||
|
|
||||||
external_ids = ['G-ADA-13B0D9D1', 'G-ADA-13A8D9CF', 'G-ADA-13B0D9CF', 'G-ADA-13B0D9CE', 'G-ADA-13A7D9D5', 'G-ADA-13ACD9D5', 'G-ADA-13B2D9D5', 'G-ADA-13AED9D4', 'G-ADA-13B1D9D4', 'G-ADA-13ACD9D3', 'G-ADA-13B1D9D3', 'G-ADA-13AED9D2', 'G-ADA-9F17D9CB', 'G-ADA-9F15D9CB', 'G-ADA']
|
|
||||||
|
|
||||||
for z in external_ids:
|
|
||||||
report_filter = """<?xml version="1.0"?> <PFWebFilter:UserFilter xmlns:PFWebFilter="http://www.pageflex.com/schemas/2004/Storefront/UserFilters/20040817" filterClass="Items"> <PFWebFilter:Step publicFieldName="Order ID" query="ExactEquals" minValue=""""" + z + """"" maxValue="" /> </PFWebFilter:UserFilter>"""
|
###REPORT ColumnFormat TESTING#####
|
||||||
print(report_filter)
|
|
||||||
|
with open("StorefrontUtilitiesConfig.xml") as f:
|
||||||
|
r = f.read()
|
||||||
|
|
||||||
|
y = bs(r, "lxml")
|
||||||
|
|
||||||
|
ClientName = []
|
||||||
|
SF_URL = []
|
||||||
|
SF_HOST = []
|
||||||
|
CLIENT_SUMMARY_TAB = []
|
||||||
|
SUMMARY_TAB = []
|
||||||
|
client_headers = []
|
||||||
|
headers = []
|
||||||
|
|
||||||
|
CLIENT_COLUMN_FORMAT = []
|
||||||
|
COLUMN_FORMAT = []
|
||||||
|
|
||||||
|
for x in y.find_all('name'):
|
||||||
|
# print(x.text)
|
||||||
|
ClientName.append(x.text)
|
||||||
|
# print(ClientName)
|
||||||
|
|
||||||
|
for w in y.find_all('client'):
|
||||||
|
for x in w.find_all('monthlyreport'):
|
||||||
|
for g in x.find_all('summarytab'):
|
||||||
|
for z in g.find_all('columnname'):
|
||||||
|
z.name = "string"
|
||||||
|
CLIENT_SUMMARY_TAB.append(z)
|
||||||
|
client_headers.append(z.text)
|
||||||
|
SUMMARY_TAB.append(CLIENT_SUMMARY_TAB)
|
||||||
|
headers.append(client_headers)
|
||||||
|
CLIENT_SUMMARY_TAB = []
|
||||||
|
client_headers = []
|
||||||
|
|
||||||
|
|
||||||
|
for w in y.find_all('client'):
|
||||||
|
for x in w.find_all('monthlyreport'):
|
||||||
|
for g in x.find_all('summarytab'):
|
||||||
|
for z in g.find_all('columnformat'):
|
||||||
|
CLIENT_COLUMN_FORMAT.append(z.text)
|
||||||
|
COLUMN_FORMAT.append(CLIENT_COLUMN_FORMAT)
|
||||||
|
CLIENT_COLUMN_FORMAT = []
|
||||||
|
|
||||||
|
|
||||||
|
option = 0
|
||||||
|
columnformat = dict.fromkeys(headers[option])
|
||||||
|
|
||||||
|
|
||||||
|
for w in y.find_all('client'):
|
||||||
|
for x in w.find_all('name'):
|
||||||
|
if x.text == ClientName[option]:
|
||||||
|
for x in w.find_all('monthlyreport'):
|
||||||
|
for g in x.find_all('summarytab'):
|
||||||
|
for z in g.find_all('columnformat'):
|
||||||
|
CLIENT_COLUMN_FORMAT.append(z.text)
|
||||||
|
|
||||||
|
count = 0
|
||||||
|
|
||||||
|
|
||||||
|
# print(columnformat)
|
||||||
|
for key in columnformat:
|
||||||
|
columnformat[key] = CLIENT_COLUMN_FORMAT[count]
|
||||||
|
count = count + 1
|
||||||
|
print(columnformat)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# external_ids = ['G-ADA-13B0D9D1', 'G-ADA-13A8D9CF']
|
||||||
|
#
|
||||||
|
# for z in external_ids:
|
||||||
|
# report_filter = """<?xml version="1.0"?> <PFWebFilter:UserFilter xmlns:PFWebFilter="http://www.pageflex.com/schemas/2004/Storefront/UserFilters/20040817" filterClass="Items"> <PFWebFilter:Step publicFieldName="Order ID" query="ExactEquals" minValue=""""" + z + """"" maxValue="" /> </PFWebFilter:UserFilter>"""
|
||||||
|
# print(report_filter)
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|||||||
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
|
||||||
|
|
||||||
|
from WriteReport import *
|
||||||
|
|
||||||
bold = Font(bold=True)
|
bold = Font(bold=True)
|
||||||
|
|
||||||
def Obtain_Ticket(URL, HOST):
|
def Obtain_Ticket(URL, HOST):
|
||||||
@@ -24,7 +26,7 @@ def Obtain_Ticket(URL, HOST):
|
|||||||
temp1 = response.split('<ObtainUserTicketResult>')
|
temp1 = response.split('<ObtainUserTicketResult>')
|
||||||
temp2 = temp1[1].split('</ObtainUserTicketResult>')
|
temp2 = temp1[1].split('</ObtainUserTicketResult>')
|
||||||
ticket = temp2[0]
|
ticket = temp2[0]
|
||||||
# print("got ticket: " + ticket)
|
print("got ticket: " + ticket)
|
||||||
return ticket
|
return ticket
|
||||||
|
|
||||||
def Release_Ticket(ticket, URL, HOST):
|
def Release_Ticket(ticket, URL, HOST):
|
||||||
@@ -38,13 +40,13 @@ def Release_Ticket(ticket, URL, HOST):
|
|||||||
</soap12:Envelope>"""
|
</soap12:Envelope>"""
|
||||||
headers = {'Host': HOST, 'Content-Type': 'application/soap+xml; charset=utf-8', 'Content-Length': 'length'}
|
headers = {'Host': HOST, 'Content-Type': 'application/soap+xml; charset=utf-8', 'Content-Length': 'length'}
|
||||||
response = requests.post(url=URL, data=ReleaseTicket, headers=headers).text
|
response = requests.post(url=URL, data=ReleaseTicket, headers=headers).text
|
||||||
# print("released ticket "+ticket)
|
print("released ticket "+ticket)
|
||||||
|
|
||||||
def Westfield():
|
def Westfield():
|
||||||
print("Westfield")
|
print("Westfield")
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
def Run_Report(ticket, URL, HOST, REPORT_FIELDS, wb, ws, ws2, DETAIL_REPORT_FIELDS):
|
def Run_Report(ticket, URL, HOST, REPORT_FIELDS, wb, ws, ws2, DETAIL_REPORT_FIELDS, columnFormat, SSheader):
|
||||||
|
|
||||||
ExternalID = []
|
ExternalID = []
|
||||||
id = []
|
id = []
|
||||||
@@ -78,19 +80,9 @@ def Run_Report(ticket, URL, HOST, REPORT_FIELDS, wb, ws, ws2, DETAIL_REPORT_FIEL
|
|||||||
print("working")
|
print("working")
|
||||||
|
|
||||||
y = bs(report, "lxml")
|
y = bs(report, "lxml")
|
||||||
results = []
|
|
||||||
|
|
||||||
# Opens report file and writes each row
|
# Opens report file and writes each row
|
||||||
for child in y.report:
|
Write_Report(y, ws, columnFormat, SSheader)
|
||||||
for childs in child:
|
|
||||||
if '$' in childs.text:
|
|
||||||
convert = childs.text
|
|
||||||
apply = convert[1:]
|
|
||||||
results.append(float(apply.replace(',','')))
|
|
||||||
else:
|
|
||||||
results.append(childs.text)
|
|
||||||
ws.append(results)
|
|
||||||
results = []
|
|
||||||
|
|
||||||
# Grabs all the Order IDs from Column A
|
# Grabs all the Order IDs from Column A
|
||||||
for cell in ws['A']:
|
for cell in ws['A']:
|
||||||
@@ -170,12 +162,13 @@ def Run_Report(ticket, URL, HOST, REPORT_FIELDS, wb, ws, ws2, DETAIL_REPORT_FIEL
|
|||||||
for row in ws:
|
for row in ws:
|
||||||
value = "=H"+str(count)+"-G"+str(count)+"-F"+str(count)
|
value = "=H"+str(count)+"-G"+str(count)+"-F"+str(count)
|
||||||
ws.cell(column=5, row=count, value=value)
|
ws.cell(column=5, row=count, value=value)
|
||||||
count =+ 1
|
count += 1
|
||||||
|
|
||||||
|
|
||||||
############# Order Details tab #############
|
############# Order Details tab #############
|
||||||
|
|
||||||
print("Getting Item Detail")
|
print("Getting Item Detail")
|
||||||
# ExternalID = ['G-ADA-13B0D9D1', 'G-ADA-13A8D9CF']
|
|
||||||
for z in ExternalID:
|
for z in ExternalID:
|
||||||
report_filter = """<filterNameOrXml><?xml version="1.0"?> <PFWebFilter:UserFilter xmlns:PFWebFilter="http://www.pageflex.com/schemas/2004/Storefront/UserFilters/20040817" filterClass="Items"> <PFWebFilter:Step publicFieldName="Order ID" query="ExactEquals" minValue=\"""" + z + """\" 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="Items"> <PFWebFilter:Step publicFieldName="Order ID" query="ExactEquals" minValue=\"""" + z + """\" maxValue="" /> </PFWebFilter:UserFilter></filterNameOrXml>"""
|
||||||
send = """<?xml version="1.0" encoding="utf-8"?>
|
send = """<?xml version="1.0" encoding="utf-8"?>
|
||||||
@@ -201,20 +194,10 @@ def Run_Report(ticket, URL, HOST, REPORT_FIELDS, wb, ws, ws2, DETAIL_REPORT_FIEL
|
|||||||
|
|
||||||
|
|
||||||
y = bs(report, "lxml")
|
y = bs(report, "lxml")
|
||||||
results = []
|
|
||||||
|
|
||||||
# Opens report file and writes each row
|
# Opens report file and writes each row
|
||||||
for child in y.report:
|
Detail_Write_Report(y, ws)
|
||||||
for childs in child:
|
|
||||||
if '$' in childs.text:
|
|
||||||
convert = childs.text
|
|
||||||
apply = convert[1:]
|
|
||||||
results.append(float(apply.replace(',', '')))
|
|
||||||
else:
|
|
||||||
results.append(childs.text)
|
|
||||||
ws2.append(results)
|
|
||||||
results = []
|
|
||||||
|
|
||||||
|
|
||||||
# Finalize Spreadsheet and save
|
# Finalize Spreadsheet and save
|
||||||
|
|
||||||
@@ -240,6 +223,8 @@ def loadMenu():
|
|||||||
DETAIL_TAB = []
|
DETAIL_TAB = []
|
||||||
client_detail_headers = []
|
client_detail_headers = []
|
||||||
detail_headers = []
|
detail_headers = []
|
||||||
|
CLIENT_COLUMN_FORMAT = []
|
||||||
|
COLUMN_FORMAT = []
|
||||||
|
|
||||||
# Open the config file
|
# Open the config file
|
||||||
with open(ConfigFile) as f:
|
with open(ConfigFile) as f:
|
||||||
@@ -278,6 +263,14 @@ def loadMenu():
|
|||||||
CLIENT_SUMMARY_TAB = []
|
CLIENT_SUMMARY_TAB = []
|
||||||
client_headers = []
|
client_headers = []
|
||||||
|
|
||||||
|
# Get Monthly Report Column Format
|
||||||
|
for w in y.find_all('client'):
|
||||||
|
for x in w.find_all('monthlyreport'):
|
||||||
|
for g in x.find_all('summarytab'):
|
||||||
|
for z in g.find_all('columnformat'):
|
||||||
|
CLIENT_COLUMN_FORMAT.append(z.text)
|
||||||
|
COLUMN_FORMAT.append(CLIENT_COLUMN_FORMAT)
|
||||||
|
CLIENT_COLUMN_FORMAT = []
|
||||||
|
|
||||||
# Get Monthly Report Item Detail Fields
|
# Get Monthly Report Item Detail Fields
|
||||||
for w in y.find_all('client'):
|
for w in y.find_all('client'):
|
||||||
@@ -292,7 +285,6 @@ def loadMenu():
|
|||||||
CLIENT_DETAIL_TAB = []
|
CLIENT_DETAIL_TAB = []
|
||||||
client_detail_headers = []
|
client_detail_headers = []
|
||||||
|
|
||||||
|
|
||||||
choice = 0
|
choice = 0
|
||||||
for x in ClientName:
|
for x in ClientName:
|
||||||
print(choice, x)
|
print(choice, x)
|
||||||
@@ -303,6 +295,22 @@ def loadMenu():
|
|||||||
if ClientName[option] == "Westfield":
|
if ClientName[option] == "Westfield":
|
||||||
Westfield()
|
Westfield()
|
||||||
|
|
||||||
|
columnformat = dict.fromkeys(headers[option])
|
||||||
|
|
||||||
|
# Get specific Column Types for chosen client
|
||||||
|
for w in y.find_all('client'):
|
||||||
|
for x in w.find_all('name'):
|
||||||
|
if x.text == ClientName[option]:
|
||||||
|
for x in w.find_all('monthlyreport'):
|
||||||
|
for g in x.find_all('summarytab'):
|
||||||
|
for z in g.find_all('columnformat'):
|
||||||
|
CLIENT_COLUMN_FORMAT.append(z.text)
|
||||||
|
# set Column Types Header Dictionary
|
||||||
|
count = 0
|
||||||
|
for key in columnformat:
|
||||||
|
columnformat[key] = CLIENT_COLUMN_FORMAT[count]
|
||||||
|
count = count + 1
|
||||||
|
|
||||||
# create new report file and add headers based on config file
|
# create new report file and add headers based on config file
|
||||||
wb = workbook.Workbook()
|
wb = workbook.Workbook()
|
||||||
ws = wb.active
|
ws = wb.active
|
||||||
@@ -317,7 +325,7 @@ def loadMenu():
|
|||||||
|
|
||||||
REPORT_FIELDS = '\n'.join(map(str, SUMMARY_TAB[option]))
|
REPORT_FIELDS = '\n'.join(map(str, SUMMARY_TAB[option]))
|
||||||
DETAIL_REPORT_FIELDS = '\n'.join(map(str, DETAIL_TAB[option]))
|
DETAIL_REPORT_FIELDS = '\n'.join(map(str, DETAIL_TAB[option]))
|
||||||
URL_HOST = [SF_URL[option], SF_HOST[option], REPORT_FIELDS, wb, ws, ws2, DETAIL_REPORT_FIELDS]
|
URL_HOST = [SF_URL[option], SF_HOST[option], REPORT_FIELDS, wb, ws, ws2, DETAIL_REPORT_FIELDS, columnformat, headers[option]]
|
||||||
return URL_HOST
|
return URL_HOST
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -329,8 +337,12 @@ def main():
|
|||||||
ws = URL_HOST[4]
|
ws = URL_HOST[4]
|
||||||
ws2 = URL_HOST[5]
|
ws2 = URL_HOST[5]
|
||||||
DETAIL_REPORT_FIELDS = URL_HOST[6]
|
DETAIL_REPORT_FIELDS = URL_HOST[6]
|
||||||
|
columnFormat = URL_HOST[7]
|
||||||
|
|
||||||
|
SSheader = URL_HOST[8]
|
||||||
|
|
||||||
ticket = Obtain_Ticket(URL, HOST)
|
ticket = Obtain_Ticket(URL, HOST)
|
||||||
Run_Report(ticket, URL, HOST, REPORT_FIELDS, wb, ws, ws2, DETAIL_REPORT_FIELDS)
|
Run_Report(ticket, URL, HOST, REPORT_FIELDS, wb, ws, ws2, DETAIL_REPORT_FIELDS, columnFormat, SSheader)
|
||||||
Release_Ticket(ticket, URL, HOST)
|
Release_Ticket(ticket, URL, HOST)
|
||||||
|
|
||||||
main()
|
main()
|
||||||
Reference in New Issue
Block a user