Broke report appending into a separate function/file. Started working on Column Format Checking Function
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.styles import Font
|
||||
|
||||
from WriteReport import *
|
||||
|
||||
bold = Font(bold=True)
|
||||
|
||||
def Obtain_Ticket(URL, HOST):
|
||||
@@ -24,7 +26,7 @@ def Obtain_Ticket(URL, HOST):
|
||||
temp1 = response.split('<ObtainUserTicketResult>')
|
||||
temp2 = temp1[1].split('</ObtainUserTicketResult>')
|
||||
ticket = temp2[0]
|
||||
# print("got ticket: " + ticket)
|
||||
print("got ticket: " + ticket)
|
||||
return ticket
|
||||
|
||||
def Release_Ticket(ticket, URL, HOST):
|
||||
@@ -38,13 +40,13 @@ def Release_Ticket(ticket, URL, HOST):
|
||||
</soap12:Envelope>"""
|
||||
headers = {'Host': HOST, 'Content-Type': 'application/soap+xml; charset=utf-8', 'Content-Length': 'length'}
|
||||
response = requests.post(url=URL, data=ReleaseTicket, headers=headers).text
|
||||
# print("released ticket "+ticket)
|
||||
print("released ticket "+ticket)
|
||||
|
||||
def Westfield():
|
||||
print("Westfield")
|
||||
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 = []
|
||||
id = []
|
||||
@@ -78,19 +80,9 @@ def Run_Report(ticket, URL, HOST, REPORT_FIELDS, wb, ws, ws2, DETAIL_REPORT_FIEL
|
||||
print("working")
|
||||
|
||||
y = bs(report, "lxml")
|
||||
results = []
|
||||
|
||||
# Opens report file and writes each row
|
||||
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 = []
|
||||
Write_Report(y, ws, columnFormat, SSheader)
|
||||
|
||||
# Grabs all the Order IDs from Column 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:
|
||||
value = "=H"+str(count)+"-G"+str(count)+"-F"+str(count)
|
||||
ws.cell(column=5, row=count, value=value)
|
||||
count =+ 1
|
||||
count += 1
|
||||
|
||||
|
||||
############# Order Details tab #############
|
||||
|
||||
print("Getting Item Detail")
|
||||
# ExternalID = ['G-ADA-13B0D9D1', 'G-ADA-13A8D9CF']
|
||||
|
||||
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>"""
|
||||
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")
|
||||
results = []
|
||||
|
||||
# Opens report file and writes each row
|
||||
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)
|
||||
ws2.append(results)
|
||||
results = []
|
||||
|
||||
# Opens report file and writes each row
|
||||
Detail_Write_Report(y, ws)
|
||||
|
||||
# Finalize Spreadsheet and save
|
||||
|
||||
@@ -240,6 +223,8 @@ def loadMenu():
|
||||
DETAIL_TAB = []
|
||||
client_detail_headers = []
|
||||
detail_headers = []
|
||||
CLIENT_COLUMN_FORMAT = []
|
||||
COLUMN_FORMAT = []
|
||||
|
||||
# Open the config file
|
||||
with open(ConfigFile) as f:
|
||||
@@ -278,6 +263,14 @@ def loadMenu():
|
||||
CLIENT_SUMMARY_TAB = []
|
||||
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
|
||||
for w in y.find_all('client'):
|
||||
@@ -292,7 +285,6 @@ def loadMenu():
|
||||
CLIENT_DETAIL_TAB = []
|
||||
client_detail_headers = []
|
||||
|
||||
|
||||
choice = 0
|
||||
for x in ClientName:
|
||||
print(choice, x)
|
||||
@@ -303,6 +295,22 @@ def loadMenu():
|
||||
if ClientName[option] == "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
|
||||
wb = workbook.Workbook()
|
||||
ws = wb.active
|
||||
@@ -317,7 +325,7 @@ def loadMenu():
|
||||
|
||||
REPORT_FIELDS = '\n'.join(map(str, SUMMARY_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
|
||||
|
||||
def main():
|
||||
@@ -329,8 +337,12 @@ def main():
|
||||
ws = URL_HOST[4]
|
||||
ws2 = URL_HOST[5]
|
||||
DETAIL_REPORT_FIELDS = URL_HOST[6]
|
||||
columnFormat = URL_HOST[7]
|
||||
|
||||
SSheader = URL_HOST[8]
|
||||
|
||||
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)
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user