Column Format is now working for both summary and item details. Load function passes client name to the client_Specific_Tabs function in ClientSpecific.py. This will allow any client customization to be done outside of the main program (in theory. I haven't actually tested this yet).

This commit is contained in:
Dan Dembinski
2019-06-25 13:47:17 -04:00
parent b8e5ae6baa
commit 28fce7e10f
5 changed files with 93 additions and 2365 deletions

16
ClientSpecific.py Normal file
View File

@@ -0,0 +1,16 @@
def client_Specific_Tabs(option):
if option == "Westfield":
Westfield()
elif option == " CCM":
CCM()
else:
return
def Westfield():
print("Neat westfield stuff will go here")
exit()
def CCM():
print("Neat CCM stuff will go here")
exit()

File diff suppressed because it is too large Load Diff

View File

@@ -98,7 +98,6 @@
<ColumnName>Date/Time Order Created</ColumnName> <ColumnName>Date/Time Order Created</ColumnName>
<ColumnFormat>DateTime</ColumnFormat> <ColumnFormat>DateTime</ColumnFormat>
<RangeName>DetailDateTime</RangeName> <RangeName>DetailDateTime</RangeName>
<ColumnFormat>None</ColumnFormat>
</Column> </Column>
<Column> <Column>
<ColumnName>Item Status</ColumnName> <ColumnName>Item Status</ColumnName>
@@ -119,7 +118,7 @@
<ColumnName>Printing Option: PrintingQuantity</ColumnName> <ColumnName>Printing Option: PrintingQuantity</ColumnName>
<ColumnHeader>Quantity</ColumnHeader> <ColumnHeader>Quantity</ColumnHeader>
<RangeName>DetailQuantity</RangeName> <RangeName>DetailQuantity</RangeName>
<ColumnFormat>None</ColumnFormat> <ColumnFormat>Integer</ColumnFormat>
</Column> </Column>
<Column> <Column>
<ColumnName>Item Price</ColumnName> <ColumnName>Item Price</ColumnName>
@@ -129,13 +128,13 @@
<Column> <Column>
<ColumnName>Data List Record Count</ColumnName> <ColumnName>Data List Record Count</ColumnName>
<RangeName>DetailDataListRecordCount</RangeName> <RangeName>DetailDataListRecordCount</RangeName>
<ColumnFormat>None</ColumnFormat> <ColumnFormat>Integer</ColumnFormat>
</Column> </Column>
<Column> <Column>
<ColumnName>Printing Option: OverrunQuantity</ColumnName> <ColumnName>Printing Option: OverrunQuantity</ColumnName>
<ColumnHeader>OverrunQuantity</ColumnHeader> <ColumnHeader>OverrunQuantity</ColumnHeader>
<RangeName>DetailOverrunQuantity</RangeName> <RangeName>DetailOverrunQuantity</RangeName>
<ColumnFormat>None</ColumnFormat> <ColumnFormat>Integer</ColumnFormat>
</Column> </Column>
<Column> <Column>
<ColumnName>Printing Option: OptionalDataList</ColumnName> <ColumnName>Printing Option: OptionalDataList</ColumnName>

View File

@@ -1,31 +1,48 @@
def Write_Report(y, ws, columnFormat, SSheader): def Write_Report(y, columnFormat, SSheader, sheet):
results = [] results = []
count = 0 count = 0
for child in y.report: for child in y.report:
for childs in child: for childs in child:
print(columnFormat[SSheader[count]]) if childs.text is not "":
asdf = Format_Check(columnFormat, SSheader, childs, count)
else:
asdf = childs.text
results.append(asdf)
count = count + 1 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 count = 0
sheet.append(results)
def Detail_Write_Report(y, ws):
results = [] results = []
for child in y.report: # def Detail_Write_Report(y, sheet):
for childs in child: # 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)
# sheet.append(results)
# results = []
def Format_Check(columnFormat, SSheader, childs, count):
check = columnFormat[SSheader[count]]
results = []
if check == "None":
return childs.text
elif check == "Currency":
if '$' in childs.text: if '$' in childs.text:
convert = childs.text convert = childs.text
apply = convert[1:] apply = convert[1:]
results.append(float(apply.replace(',', ''))) results.append(float(apply.replace(',', '')))
return results[0]
else: else:
results.append(childs.text) return float(childs.text)
ws.append(results) elif check == "Integer":
results = [] return int(childs.text)
else:
return childs.text

56
main.py
View File

@@ -1,10 +1,9 @@
import requests import requests
from bs4 import BeautifulSoup as bs from bs4 import BeautifulSoup as bs
# import csv
from openpyxl import workbook from openpyxl import workbook
from openpyxl.styles import Font from openpyxl.styles import Font
from WriteReport import * from WriteReport import *
from ClientSpecific import *
bold = Font(bold=True) bold = Font(bold=True)
@@ -42,11 +41,8 @@ def Release_Ticket(ticket, URL, HOST):
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():
print("Westfield")
exit()
def Run_Report(ticket, URL, HOST, REPORT_FIELDS, wb, ws, ws2, DETAIL_REPORT_FIELDS, columnFormat, SSheader): def Run_Report(ticket, URL, HOST, REPORT_FIELDS, wb, ws, ws2, DETAIL_REPORT_FIELDS, summary_columnFormat, summary_SSheader, detail_columnFormat, detail_SSheader):
ExternalID = [] ExternalID = []
id = [] id = []
@@ -82,7 +78,8 @@ def Run_Report(ticket, URL, HOST, REPORT_FIELDS, wb, ws, ws2, DETAIL_REPORT_FIEL
y = bs(report, "lxml") y = bs(report, "lxml")
# Opens report file and writes each row # Opens report file and writes each row
Write_Report(y, ws, columnFormat, SSheader) sheet = ws
Write_Report(y, summary_columnFormat, summary_SSheader, sheet)
# 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']:
@@ -197,7 +194,8 @@ def Run_Report(ticket, URL, HOST, REPORT_FIELDS, wb, ws, ws2, DETAIL_REPORT_FIEL
# Opens report file and writes each row # Opens report file and writes each row
Detail_Write_Report(y, ws) sheet = ws2
Write_Report(y, detail_columnFormat, detail_SSheader, sheet)
# Finalize Spreadsheet and save # Finalize Spreadsheet and save
@@ -225,6 +223,7 @@ def loadMenu():
detail_headers = [] detail_headers = []
CLIENT_COLUMN_FORMAT = [] CLIENT_COLUMN_FORMAT = []
COLUMN_FORMAT = [] COLUMN_FORMAT = []
detail_columnformat = []
# Open the config file # Open the config file
with open(ConfigFile) as f: with open(ConfigFile) as f:
@@ -292,12 +291,11 @@ def loadMenu():
option = int(input()) option = int(input())
if ClientName[option] == "Westfield": client_Specific_Tabs(ClientName[option])
Westfield()
columnformat = dict.fromkeys(headers[option]) summary_columnformat = dict.fromkeys(headers[option])
# Get specific Column Types for chosen client # Get specific Summary Column Types for chosen client
for w in y.find_all('client'): for w in y.find_all('client'):
for x in w.find_all('name'): for x in w.find_all('name'):
if x.text == ClientName[option]: if x.text == ClientName[option]:
@@ -305,10 +303,27 @@ def loadMenu():
for g in x.find_all('summarytab'): for g in x.find_all('summarytab'):
for z in g.find_all('columnformat'): for z in g.find_all('columnformat'):
CLIENT_COLUMN_FORMAT.append(z.text) CLIENT_COLUMN_FORMAT.append(z.text)
# set Column Types Header Dictionary # set Summary Column Types Header Dictionary
count = 0 count = 0
for key in columnformat: for key in summary_columnformat:
columnformat[key] = CLIENT_COLUMN_FORMAT[count] summary_columnformat[key] = CLIENT_COLUMN_FORMAT[count]
count = count + 1
CLIENT_COLUMN_FORMAT = []
# Get specific Detail 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('detailtab'):
for z in g.find_all('columnformat'):
CLIENT_COLUMN_FORMAT.append(z.text)
detail_columnformat = dict.fromkeys(detail_headers[option])
# set Detail Column Types Header Dictionary
count = 0
for key in detail_columnformat:
detail_columnformat[key] = CLIENT_COLUMN_FORMAT[count]
count = count + 1 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
@@ -322,10 +337,9 @@ def loadMenu():
# converts summary_tab values to a string, adds everything to the URL_HOST array and returns it # converts summary_tab values to a string, adds everything to the URL_HOST array and returns it
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, columnformat, headers[option]] URL_HOST = [SF_URL[option], SF_HOST[option], REPORT_FIELDS, wb, ws, ws2, DETAIL_REPORT_FIELDS, summary_columnformat, headers[option], detail_columnformat, detail_headers[option]]
return URL_HOST return URL_HOST
def main(): def main():
@@ -337,12 +351,14 @@ 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] summary_columnFormat = URL_HOST[7]
SSheader = URL_HOST[8] summary_SSheader = URL_HOST[8]
detail_columnFormat = URL_HOST[9]
detail_SSheader = URL_HOST[10]
ticket = Obtain_Ticket(URL, HOST) ticket = Obtain_Ticket(URL, HOST)
Run_Report(ticket, URL, HOST, REPORT_FIELDS, wb, ws, ws2, DETAIL_REPORT_FIELDS, columnFormat, SSheader) Run_Report(ticket, URL, HOST, REPORT_FIELDS, wb, ws, ws2, DETAIL_REPORT_FIELDS, summary_columnFormat, summary_SSheader, detail_columnFormat, detail_SSheader)
Release_Ticket(ticket, URL, HOST) Release_Ticket(ticket, URL, HOST)
main() main()