Exports as XLSX file now. Started working on Report Filters
This commit is contained in:
File diff suppressed because one or more lines are too long
51
main.py
51
main.py
@@ -1,7 +1,8 @@
|
|||||||
import requests
|
import requests
|
||||||
from bs4 import BeautifulSoup as bs
|
from bs4 import BeautifulSoup as bs
|
||||||
import csv
|
# import csv
|
||||||
|
from openpyxl import workbook
|
||||||
|
from openpyxl.styles import Font
|
||||||
|
|
||||||
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"?>
|
||||||
@@ -37,18 +38,30 @@ 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, REPORT_FIELDS):
|
def Run_Report(ticket, URL, HOST, REPORT_FIELDS, ws, wb):
|
||||||
|
|
||||||
|
report_filter = """<?xml version="1.0"?>
|
||||||
|
<PFWebFilter:UserFilter xmlns:PFWebFilter="http://www.pageflex.com/schemas/2004/Storefront/UserFilters/20040817" filterClass="Orders">
|
||||||
|
<PFWebFilter:Step publicFieldName="Balance Due" query="ExactUnequals" minValue="0.00" maxValue=""/>
|
||||||
|
<PFWebFilter:Step publicFieldName="Order Status" query="ExactEquals" minValue="Completed" maxValue=""/>
|
||||||
|
</PFWebFilter:UserFilter>"""
|
||||||
|
|
||||||
|
|
||||||
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">
|
||||||
<soap12:Body>
|
<soap12:Body>
|
||||||
<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>
|
||||||
|
<archived>false</archived>
|
||||||
|
<filterNameOrXML>"Order Status 'Completed'"</filterNameOrXML>
|
||||||
<columnNames>"""+REPORT_FIELDS+"""</columnNames>
|
<columnNames>"""+REPORT_FIELDS+"""</columnNames>
|
||||||
</GetReport>
|
</GetReport>
|
||||||
</soap12:Body>
|
</soap12:Body>
|
||||||
</soap12:Envelope>"""
|
</soap12:Envelope>"""
|
||||||
|
print(send)
|
||||||
|
|
||||||
|
|
||||||
headers = {'Host': HOST, 'Content-Type': 'application/soap+xml; charset=utf-8', 'Content-Length': 'length'}
|
headers = {'Host': HOST, 'Content-Type': 'application/soap+xml; charset=utf-8', 'Content-Length': 'length'}
|
||||||
response = requests.post(url=URL, data=send, headers=headers).text
|
response = requests.post(url=URL, data=send, headers=headers).text
|
||||||
@@ -62,13 +75,12 @@ def Run_Report(ticket, URL, HOST, REPORT_FIELDS):
|
|||||||
results = []
|
results = []
|
||||||
|
|
||||||
# Opens report file and writes each row
|
# Opens report file and writes each row
|
||||||
with open('report.csv', mode='a') as out:
|
for child in y.report:
|
||||||
out_writer = csv.writer(out, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL)
|
for childs in child:
|
||||||
for child in y.report:
|
results.append(childs.text)
|
||||||
for childs in child:
|
ws.append(results)
|
||||||
results.append(childs.text)
|
results = []
|
||||||
out_writer.writerow(results)
|
wb.save('report.xlsx')
|
||||||
results = []
|
|
||||||
|
|
||||||
def loadMenu():
|
def loadMenu():
|
||||||
|
|
||||||
@@ -126,13 +138,18 @@ def loadMenu():
|
|||||||
option = int(input())
|
option = int(input())
|
||||||
|
|
||||||
# create new report file and adds headers based on config file
|
# create new report file and adds headers based on config file
|
||||||
with open('report.csv', mode='w') as out:
|
wb = workbook.Workbook()
|
||||||
out_writer = csv.writer(out, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL)
|
ws = wb.active
|
||||||
out_writer.writerow(headers[option])
|
ws.title = "Order Summary"
|
||||||
|
ws.append(headers[option])
|
||||||
|
bold = Font(bold=True)
|
||||||
|
for cell in ws["1:1"]:
|
||||||
|
cell.font = bold
|
||||||
|
# cell.row_dimensions.width = 25
|
||||||
|
|
||||||
# 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]))
|
||||||
URL_HOST = [SF_URL[option], SF_HOST[option], REPORT_FIELDS]
|
URL_HOST = [SF_URL[option], SF_HOST[option], REPORT_FIELDS, wb, ws]
|
||||||
return URL_HOST
|
return URL_HOST
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -140,8 +157,10 @@ def main():
|
|||||||
URL = URL_HOST[0]
|
URL = URL_HOST[0]
|
||||||
HOST = URL_HOST[1]
|
HOST = URL_HOST[1]
|
||||||
REPORT_FIELDS = URL_HOST[2]
|
REPORT_FIELDS = URL_HOST[2]
|
||||||
|
wb = URL_HOST[3]
|
||||||
|
ws = URL_HOST[4]
|
||||||
ticket = Obtain_Ticket(URL, HOST)
|
ticket = Obtain_Ticket(URL, HOST)
|
||||||
Run_Report(ticket, URL, HOST, REPORT_FIELDS)
|
Run_Report(ticket, URL, HOST, REPORT_FIELDS, ws, wb)
|
||||||
Release_Ticket(ticket, URL, HOST)
|
Release_Ticket(ticket, URL, HOST)
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user