From ecb9757fb5cbf7b58f2bca8c3142cabfced01f79 Mon Sep 17 00:00:00 2001 From: Dan Dembinski Date: Fri, 28 Jun 2019 14:23:10 -0400 Subject: [PATCH] Started moving SFU over to Flask --- app/SFU.py | 3 + app/__init__.py | 7 + app/routes.py | 13 ++ app/templates/index.html | 12 ++ main.py | 284 ++++++++++++++++++++------------------- 5 files changed, 184 insertions(+), 135 deletions(-) create mode 100644 app/SFU.py create mode 100644 app/__init__.py create mode 100644 app/routes.py create mode 100644 app/templates/index.html diff --git a/app/SFU.py b/app/SFU.py new file mode 100644 index 0000000..aea06d6 --- /dev/null +++ b/app/SFU.py @@ -0,0 +1,3 @@ +from app import app + + diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..a404f92 --- /dev/null +++ b/app/__init__.py @@ -0,0 +1,7 @@ +from flask import Flask + +app = Flask(__name__) + +from app import routes + + diff --git a/app/routes.py b/app/routes.py new file mode 100644 index 0000000..6a89426 --- /dev/null +++ b/app/routes.py @@ -0,0 +1,13 @@ +from app import app +from flask import render_template +from main import loadClients + +@app.route('/') +@app.route('/index') + +def index(): + ClientName = [] + + ClientName = loadClients() + + return render_template('index.html', title='SFU', ClientName=ClientName) \ No newline at end of file diff --git a/app/templates/index.html b/app/templates/index.html new file mode 100644 index 0000000..c3c8acf --- /dev/null +++ b/app/templates/index.html @@ -0,0 +1,12 @@ + + + + + Title + + + {% for x in ClientName %} + {{ ClientName }}
+ {% endfor %} + + \ No newline at end of file diff --git a/main.py b/main.py index f0173ff..90b9cdd 100644 --- a/main.py +++ b/main.py @@ -7,6 +7,7 @@ from ClientSpecific import * + def Obtain_Ticket(URL, HOST): GetTicket = """ @@ -256,23 +257,12 @@ def Run_Report(ticket, URL, HOST, REPORT_FIELDS, wb, ws, ws2, DETAIL_REPORT_FIEL Format_Report(ws2, detail_SSheader, detail_columnFormat) Save_Report(wb, ws, ws2, ws3, summary_SSheader, detail_SSheader, summary_columnFormat) -def loadMenu(): +def loadClients(): - ConfigFile = "StorefrontUtilitiesConfig.xml" + ConfigFile = "../StorefrontUtilitiesConfig.xml" ClientName = [] SF_URL = [] SF_HOST = [] - CLIENT_SUMMARY_TAB = [] - SUMMARY_TAB = [] - headers = [] - client_headers = [] - CLIENT_DETAIL_TAB = [] - DETAIL_TAB = [] - client_detail_headers = [] - detail_headers = [] - CLIENT_COLUMN_FORMAT = [] - COLUMN_FORMAT = [] - detail_columnformat = [] # Open the config file with open(ConfigFile) as f: @@ -280,134 +270,158 @@ def loadMenu(): y = bs(r, "lxml") -# Get list of clients + # Get list of clients for x in y.find_all('name'): # print(x.text) ClientName.append(x.text) -# Get Storefront API URls - for x in y.find_all('storefrontapiurl'): - # print(x) - SF_URL.append(x.text) + # # Get Storefront API URls + # for x in y.find_all('storefrontapiurl'): + # # print(x) + # SF_URL.append(x.text) + # + # # Get Storefront Host URLs + # for x in SF_URL: + # temp1 = x.split('://') + # temp2 = temp1[1].split('/') + # HOST = (temp2[0]) + # SF_HOST.append(HOST) -# Get Storefront Host URLs - for x in SF_URL: - temp1 = x.split('://') - temp2 = temp1[1].split('/') - HOST = (temp2[0]) - SF_HOST.append(HOST) + return(ClientName) -# Get Monthly Report Summary Fields - 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 = [] -# 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 = [] +# def loadMenu(): +# +# ConfigFile = "StorefrontUtilitiesConfig.xml" +# ClientName = [] +# SF_URL = [] +# SF_HOST = [] +# CLIENT_SUMMARY_TAB = [] +# SUMMARY_TAB = [] +# headers = [] +# client_headers = [] +# CLIENT_DETAIL_TAB = [] +# DETAIL_TAB = [] +# client_detail_headers = [] +# detail_headers = [] +# CLIENT_COLUMN_FORMAT = [] +# COLUMN_FORMAT = [] +# detail_columnformat = [] +# -# Get Monthly Report Item Detail Fields - for w in y.find_all('client'): - for x in w.find_all('monthlyreport'): - for g in x.find_all('detailtab'): - for z in g.find_all('columnname'): - z.name = "string" - CLIENT_DETAIL_TAB.append(z) - client_detail_headers.append(z.text) - DETAIL_TAB.append(CLIENT_DETAIL_TAB) - detail_headers.append(client_detail_headers) - CLIENT_DETAIL_TAB = [] - client_detail_headers = [] - - choice = 0 - for x in ClientName: - print(choice, x) - choice = choice + 1 - - option = int(input()) - - client_Specific_Tabs(ClientName[option]) - - summary_columnformat = dict.fromkeys(headers[option]) - -# Get specific Summary 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 Summary Column Types Header Dictionary - count = 0 - for key in summary_columnformat: - 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 - -# create new report file and add headers based on config file - wb = workbook.Workbook() - ws = wb.active - ws.title = "Order Summary" - ws.append(headers[option]) - - ws2 = wb.create_sheet("Item Detail") - ws2.append(detail_headers[option]) - -# 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])) - 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, 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 +# +# +# # Get Monthly Report Summary Fields +# 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 = [] +# +# # 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'): +# for x in w.find_all('monthlyreport'): +# for g in x.find_all('detailtab'): +# for z in g.find_all('columnname'): +# z.name = "string" +# CLIENT_DETAIL_TAB.append(z) +# client_detail_headers.append(z.text) +# DETAIL_TAB.append(CLIENT_DETAIL_TAB) +# detail_headers.append(client_detail_headers) +# CLIENT_DETAIL_TAB = [] +# client_detail_headers = [] +# +# choice = 0 +# for x in ClientName: +# print(choice, x) +# choice = choice + 1 +# +# option = int(input()) +# +# client_Specific_Tabs(ClientName[option]) +# +# summary_columnformat = dict.fromkeys(headers[option]) +# +# # Get specific Summary 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 Summary Column Types Header Dictionary +# count = 0 +# for key in summary_columnformat: +# 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 +# +# # create new report file and add headers based on config file +# wb = workbook.Workbook() +# ws = wb.active +# ws.title = "Order Summary" +# ws.append(headers[option]) +# +# ws2 = wb.create_sheet("Item Detail") +# ws2.append(detail_headers[option]) +# +# # 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])) +# 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, 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