diff --git a/ClientSpecific.py b/ClientSpecific.py index b9f2ab8..29d8619 100644 --- a/ClientSpecific.py +++ b/ClientSpecific.py @@ -1,16 +1,62 @@ -def client_Specific_Tabs(option): +import requests +from bs4 import BeautifulSoup as bs +from datetime import datetime, timedelta +import time + +def client_Specific_Tabs(option, wb, ticket, HOST, URL): + print("Client Specific") if option == "Westfield": Westfield() - elif option == " CCM": - CCM() + elif option == "CCM": + CCM(wb, ticket, HOST, URL) else: return def Westfield(): - print("Neat westfield stuff will go here") - exit() + return -def CCM(): - print("Neat CCM stuff will go here") - exit() \ No newline at end of file +def CCM(wb, ticket, HOST, URL): + + print("CCM is starting") + + REPORT_FIELDS = 'Order ID, Order Status' + + now = datetime.now() + first = now.replace(day=1) + lastMonth = first - timedelta(days=1) + previous = lastMonth.strftime("%m/01/%Y") + now = now.strftime("%m/%d/%Y") + + ws4 = wb.create_sheet("Downloaded Items") + + report_filter = """ <?xml version="1.0"?> <PFWebFilter:UserFilter xmlns:PFWebFilter="http://www.pageflex.com/schemas/2004/Storefront/UserFilters/20040817" filterClass="Items"> <PFWebFilter:Step publicFieldName="Date/Time Created" query="IsBetweenDate" minValue=""" + '"' + previous + ' 00:00"' + """ maxValue=""" + '"' + now + ' 00:00"' """/> <PFWebFilter:Step publicFieldName="PrintingFreeDownloadOnly" query="ExactEquals" minValue="download" maxValue="" /> </PFWebFilter:UserFilter> + """ + + send = """ + + + + """ + ticket + """ + Items + false + """ + report_filter + """ + """ + REPORT_FIELDS + """ + + + """ + + 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 + + temp1 = response.split('') + temp2 = temp1[1].split('') + report = (temp2[0]) + + y = bs(report, "lxml") + + ws4.append(report) + + return diff --git a/XMLTesting.py b/XMLTesting.py index e271fde..a63f42f 100644 --- a/XMLTesting.py +++ b/XMLTesting.py @@ -1,74 +1,136 @@ -from bs4 import BeautifulSoup as bs -# import csv -from openpyxl import workbook +import requests +from datetime import datetime, timedelta +import time +from main import Obtain_Ticket, Release_Ticket + + +URL = "http://ccm.gli.us.com/store/storefrontapi.asmx" +temp1 = URL.split('://') +temp2 = temp1[1].split('/') +HOST = (temp2[0]) + +ticket = Obtain_Ticket(URL, HOST) + +print("CCM is starting") +now = datetime.now() +first = now.replace(day=1) +lastMonth = first - timedelta(days=1) +previous = lastMonth.strftime("%m/01/%Y") +now = now.strftime("%m/%d/%Y") + + +REPORT_FIELDS = 'Order ID, Order Status' + +# ws4 = wb.create_sheet("Downloaded Items") + +report_filter = """ <?xml version="1.0"?> <PFWebFilter:UserFilter xmlns:PFWebFilter="http://www.pageflex.com/schemas/2004/Storefront/UserFilters/20040817" filterClass="Items"> <PFWebFilter:Step publicFieldName="Date/Time Created" query="IsBetweenDate" minValue=""" + '"' + previous + ' 00:00"' + """ maxValue=""" + '"' + now + ' 00:00"' """/> <PFWebFilter:Step publicFieldName="PrintingFreeDownloadOnly" query="ExactEquals" minValue="download" maxValue="" /> </PFWebFilter:UserFilter> + """ + + +send = """ + + + + """ + ticket + """ + Items + false + """ + report_filter + """ + """+REPORT_FIELDS+""" + + + """ + +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 -###REPORT ColumnFormat TESTING##### +temp1 = response.split('') +temp2 = temp1[1].split('') +report = (temp2[0]) -with open("StorefrontUtilitiesConfig.xml") as f: - r = f.read() +print(report) -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 = [] +Release_Ticket(ticket, URL, HOST) -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 +# from bs4 import BeautifulSoup as bs +# # import csv +# from openpyxl import workbook +# +# +# +# ###REPORT ColumnFormat TESTING##### +# +# 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) -for key in columnformat: - columnformat[key] = CLIENT_COLUMN_FORMAT[count] - count = count + 1 -print(columnformat) diff --git a/app/routes.py b/app/routes.py index 455dbec..9ef83f7 100644 --- a/app/routes.py +++ b/app/routes.py @@ -38,7 +38,7 @@ def runReport(): ticket = Obtain_Ticket(SF_URL, SF_HOST) Run_Report(ticket, SF_URL, SF_HOST, REPORT_FIELDS, wb, ws, ws2, DETAIL_REPORT_FIELDS, summary_columnformat, headers[0], - detail_columnformat, detail_headers[0]) + detail_columnformat, detail_headers[0], client) Release_Ticket(ticket, SF_URL, SF_HOST) diff --git a/main.py b/main.py index 04209cc..6744d2f 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,6 @@ +## SET FLASK_APP=SFU.py +##Flask Run + import requests from bs4 import BeautifulSoup as bs from openpyxl import workbook @@ -22,7 +25,7 @@ def Obtain_Ticket(URL, HOST): headers = {'Host': HOST, 'Content-Type': 'application/soap+xml; charset=utf-8', 'Content-Length': 'length'} response = requests.post(url=URL, data=GetTicket, headers=headers).text - # print(response) + #print(response) temp1 = response.split('') temp2 = temp1[1].split('') ticket = temp2[0] @@ -43,7 +46,7 @@ def Release_Ticket(ticket, URL, HOST): #("released ticket "+ticket) -def Run_Report(ticket, URL, HOST, REPORT_FIELDS, wb, ws, ws2, DETAIL_REPORT_FIELDS, summary_columnFormat, summary_SSheader, detail_columnFormat, detail_SSheader): +def Run_Report(ticket, URL, HOST, REPORT_FIELDS, wb, ws, ws2, DETAIL_REPORT_FIELDS, summary_columnFormat, summary_SSheader, detail_columnFormat, detail_SSheader, client): ExternalID = [] id = [] @@ -204,6 +207,7 @@ def Run_Report(ticket, URL, HOST, REPORT_FIELDS, wb, ws, ws2, DETAIL_REPORT_FIEL """ + 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 temp1 = response.split('') @@ -237,26 +241,49 @@ def Run_Report(ticket, URL, HOST, REPORT_FIELDS, wb, ws, ws2, DETAIL_REPORT_FIEL ws3['A1'] = "Product Name" ws3['B1'] = "Quantity" ws3['C1'] = "Item Price" + + PrintQuantity = 0 + for x in detail_SSheader: + if x != "Printing Option: PrintingQuantity": + PrintQuantity += 1 + else: + break + PrintQuantity += 1 + + ItemPrice = 0 + for x in detail_SSheader: + if x != "Item Price": + ItemPrice += 1 + else: + break + ItemPrice += 1 + + PrintQuantityColumn = get_column_letter(PrintQuantity) + ItemPriceColumn = get_column_letter(ItemPrice) + count = 1 for x in ws3: - value = "=SUMIF('Item Detail'!F:F,A"+str(count)+",'Item Detail'!G:G)" + value = "=SUMIF('Item Detail'!F:F,A"+str(count)+",'Item Detail'!" + PrintQuantityColumn + ":" + PrintQuantityColumn + ")" if count != 1: ws3.cell(column = 2, row = count, value = value) count += 1 count = 1 for x in ws3: - value = "=SUMIF('Item Detail'!F:F,A"+str(count)+",'Item Detail'!H:H)" + value = "=SUMIF('Item Detail'!F:F,A"+str(count)+",'Item Detail'!" + ItemPriceColumn + ":" + ItemPriceColumn + ")" if count != 1: ws3.cell(column = 3, row = count, value = value) count += 1 + client_Specific_Tabs(client, wb, ticket, HOST, URL) # Finalize Spreadsheet and save Format_Report(ws, summary_SSheader, summary_columnFormat) Format_Report(ws2, detail_SSheader, detail_columnFormat) Save_Report(wb, ws, ws2, ws3, summary_SSheader, detail_SSheader, summary_columnFormat) + + def loadClients(): ConfigFile = "../StorefrontUtilitiesConfig.xml" @@ -293,6 +320,10 @@ def GetClientConfig(Client): summary_columnformat = [] detail_columnformat = [] + if Client == 'Westfield': + Westfield() + return + # Loads config file and reads in XML ConfigFile = "../StorefrontUtilitiesConfig.xml" @@ -364,6 +395,7 @@ def GetClientConfig(Client): REPORT_FIELDS = '\n'.join(map(str, SUMMARY_TAB)) DETAIL_REPORT_FIELDS = '\n'.join(map(str, DETAIL_TAB)) + # Get specific Summary Column Types for chosen client for w in y.find_all('client'): for x in w.find_all('name'): @@ -412,33 +444,4 @@ def GetClientConfig(Client): ClientConfig = [SF_URL, SF_HOST, REPORT_FIELDS, DETAIL_REPORT_FIELDS, summary_columnformat, headers, detail_columnformat, detail_headers, wb, ws, ws2] - return ClientConfig - - -# def loadMenu(): -# -# Since I forgot what this is...It passes ClientName over to ClientSpecific.py to see if they have any custom tabs. -# client_Specific_Tabs(ClientName[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 - -# def main(): -# URL_HOST = loadMenu() -# URL = URL_HOST[0] -# HOST = URL_HOST[1] -# REPORT_FIELDS = URL_HOST[2] -# wb = URL_HOST[3] -# ws = URL_HOST[4] -# ws2 = URL_HOST[5] -# DETAIL_REPORT_FIELDS = URL_HOST[6] -# summary_columnFormat = URL_HOST[7] -# -# summary_SSheader = URL_HOST[8] -# detail_columnFormat = URL_HOST[9] -# detail_SSheader = URL_HOST[10] -# -# ticket = Obtain_Ticket(URL, HOST) -# 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) -# -# main() \ No newline at end of file + return ClientConfig \ No newline at end of file