Loads Summary Tab report fields from URL and generates report. Also added headers to CSV output
This commit is contained in:
139
XMLTesting.py
139
XMLTesting.py
File diff suppressed because one or more lines are too long
66
main.py
66
main.py
@@ -3,11 +3,6 @@ from bs4 import BeautifulSoup as bs
|
|||||||
import csv
|
import csv
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ClientName = []
|
|
||||||
SF_URL = []
|
|
||||||
SF_HOST = []
|
|
||||||
|
|
||||||
def Obtain_Ticket(URL, HOST):
|
def Obtain_Ticket(URL, HOST):
|
||||||
GetTicket = """<?xml version="1.0" encoding="utf-8"?>
|
GetTicket = """<?xml version="1.0" encoding="utf-8"?>
|
||||||
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
|
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
|
||||||
@@ -42,7 +37,7 @@ 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 Run_Report(ticket, URL, HOST):
|
def Run_Report(ticket, URL, HOST, REPORT_FIELDS):
|
||||||
|
|
||||||
send = """<?xml version="1.0" encoding="utf-8"?>
|
send = """<?xml version="1.0" encoding="utf-8"?>
|
||||||
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
|
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
|
||||||
@@ -50,10 +45,7 @@ def Run_Report(ticket, URL, HOST):
|
|||||||
<GetReport xmlns="http://www.pageflex.com/XmlWebServices/2004/StorefrontAPI/20041111">
|
<GetReport xmlns="http://www.pageflex.com/XmlWebServices/2004/StorefrontAPI/20041111">
|
||||||
<token>"""+ticket+"""</token>
|
<token>"""+ticket+"""</token>
|
||||||
<reportName>Orders</reportName>
|
<reportName>Orders</reportName>
|
||||||
<columnNames>
|
<columnNames>"""+REPORT_FIELDS+"""</columnNames>
|
||||||
<string>Order ID</string>
|
|
||||||
<string>Order Price</string>
|
|
||||||
</columnNames>
|
|
||||||
</GetReport>
|
</GetReport>
|
||||||
</soap12:Body>
|
</soap12:Body>
|
||||||
</soap12:Envelope>"""
|
</soap12:Envelope>"""
|
||||||
@@ -69,7 +61,8 @@ def Run_Report(ticket, URL, HOST):
|
|||||||
y = bs(report, "lxml")
|
y = bs(report, "lxml")
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
with open('report.csv', mode='w') as out:
|
# Opens report file and writes each row
|
||||||
|
with open('report.csv', mode='a') as out:
|
||||||
out_writer = csv.writer(out, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL)
|
out_writer = csv.writer(out, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL)
|
||||||
for child in y.report:
|
for child in y.report:
|
||||||
for childs in child:
|
for childs in child:
|
||||||
@@ -79,27 +72,51 @@ def Run_Report(ticket, URL, HOST):
|
|||||||
|
|
||||||
def loadMenu():
|
def loadMenu():
|
||||||
|
|
||||||
|
ClientName = []
|
||||||
|
SF_URL = []
|
||||||
|
SF_HOST = []
|
||||||
|
CLIENT_SUMMARY_TAB = []
|
||||||
|
SUMMARY_TAB = []
|
||||||
|
headers = []
|
||||||
|
client_headers = []
|
||||||
|
|
||||||
|
# Open the config file
|
||||||
with open("Config_ORIG.xml") as f:
|
with open("Config_ORIG.xml") as f:
|
||||||
r = f.read()
|
r = f.read()
|
||||||
|
|
||||||
y = bs(r, "lxml")
|
y = bs(r, "lxml")
|
||||||
|
|
||||||
|
# Get list of clients
|
||||||
for x in y.find_all('name'):
|
for x in y.find_all('name'):
|
||||||
# print(x.text)
|
# print(x.text)
|
||||||
ClientName.append(x.text)
|
ClientName.append(x.text)
|
||||||
# print(ClientName)
|
|
||||||
|
|
||||||
|
# Get Storefront API URls
|
||||||
for x in y.find_all('storefrontapiurl'):
|
for x in y.find_all('storefrontapiurl'):
|
||||||
# print(x)
|
# print(x)
|
||||||
SF_URL.append(x.text)
|
SF_URL.append(x.text)
|
||||||
# print(SF_URL)
|
|
||||||
|
|
||||||
|
# Get Storefront Host URLs
|
||||||
for x in SF_URL:
|
for x in SF_URL:
|
||||||
temp1 = x.split('://')
|
temp1 = x.split('://')
|
||||||
temp2 = temp1[1].split('/')
|
temp2 = temp1[1].split('/')
|
||||||
HOST = (temp2[0])
|
HOST = (temp2[0])
|
||||||
SF_HOST.append(HOST)
|
SF_HOST.append(HOST)
|
||||||
# print(SF_HOST)
|
|
||||||
|
|
||||||
|
# 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 = []
|
||||||
|
|
||||||
|
|
||||||
choice = 0
|
choice = 0
|
||||||
for x in ClientName:
|
for x in ClientName:
|
||||||
@@ -107,17 +124,24 @@ def loadMenu():
|
|||||||
choice = choice + 1
|
choice = choice + 1
|
||||||
|
|
||||||
option = int(input())
|
option = int(input())
|
||||||
print(SF_URL[option])
|
|
||||||
print(SF_HOST[option])
|
|
||||||
|
|
||||||
return SF_URL[option], SF_HOST[option]
|
# create new report file and adds headers based on config file
|
||||||
|
with open('report.csv', mode='w') as out:
|
||||||
|
out_writer = csv.writer(out, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL)
|
||||||
|
out_writer.writerow(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]))
|
||||||
|
URL_HOST = [SF_URL[option], SF_HOST[option], REPORT_FIELDS]
|
||||||
|
return URL_HOST
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
loadMenu()
|
URL_HOST = loadMenu()
|
||||||
URL = 'http://soprema.gli.us.com/Store/storefrontapi.asmx'
|
URL = URL_HOST[0]
|
||||||
HOST = 'soprema.gli.us.com'
|
HOST = URL_HOST[1]
|
||||||
|
REPORT_FIELDS = URL_HOST[2]
|
||||||
ticket = Obtain_Ticket(URL, HOST)
|
ticket = Obtain_Ticket(URL, HOST)
|
||||||
Run_Report(ticket, URL, HOST)
|
Run_Report(ticket, URL, HOST, REPORT_FIELDS)
|
||||||
Release_Ticket(ticket, URL, HOST)
|
Release_Ticket(ticket, URL, HOST)
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user