Exports as XLSX file now. Started working on Report Filters
This commit is contained in:
51
main.py
51
main.py
@@ -1,7 +1,8 @@
|
||||
import requests
|
||||
from bs4 import BeautifulSoup as bs
|
||||
import csv
|
||||
|
||||
# import csv
|
||||
from openpyxl import workbook
|
||||
from openpyxl.styles import Font
|
||||
|
||||
def Obtain_Ticket(URL, HOST):
|
||||
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
|
||||
# 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"?>
|
||||
<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>
|
||||
<GetReport xmlns="http://www.pageflex.com/XmlWebServices/2004/StorefrontAPI/20041111">
|
||||
<token>"""+ticket+"""</token>
|
||||
<reportName>Orders</reportName>
|
||||
<archived>false</archived>
|
||||
<filterNameOrXML>"Order Status 'Completed'"</filterNameOrXML>
|
||||
<columnNames>"""+REPORT_FIELDS+"""</columnNames>
|
||||
</GetReport>
|
||||
</soap12:Body>
|
||||
</soap12:Envelope>"""
|
||||
print(send)
|
||||
|
||||
|
||||
headers = {'Host': HOST, 'Content-Type': 'application/soap+xml; charset=utf-8', 'Content-Length': 'length'}
|
||||
response = requests.post(url=URL, data=send, headers=headers).text
|
||||
@@ -62,13 +75,12 @@ def Run_Report(ticket, URL, HOST, REPORT_FIELDS):
|
||||
results = []
|
||||
|
||||
# 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)
|
||||
for child in y.report:
|
||||
for childs in child:
|
||||
results.append(childs.text)
|
||||
out_writer.writerow(results)
|
||||
results = []
|
||||
for child in y.report:
|
||||
for childs in child:
|
||||
results.append(childs.text)
|
||||
ws.append(results)
|
||||
results = []
|
||||
wb.save('report.xlsx')
|
||||
|
||||
def loadMenu():
|
||||
|
||||
@@ -126,13 +138,18 @@ def loadMenu():
|
||||
option = int(input())
|
||||
|
||||
# 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])
|
||||
wb = workbook.Workbook()
|
||||
ws = wb.active
|
||||
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
|
||||
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
|
||||
|
||||
def main():
|
||||
@@ -140,8 +157,10 @@ def main():
|
||||
URL = URL_HOST[0]
|
||||
HOST = URL_HOST[1]
|
||||
REPORT_FIELDS = URL_HOST[2]
|
||||
wb = URL_HOST[3]
|
||||
ws = URL_HOST[4]
|
||||
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)
|
||||
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user