125 lines
4.1 KiB
Python
125 lines
4.1 KiB
Python
import requests
|
|
from bs4 import BeautifulSoup as bs
|
|
import csv
|
|
|
|
|
|
|
|
ClientName = []
|
|
SF_URL = []
|
|
SF_HOST = []
|
|
|
|
def Obtain_Ticket(URL, HOST):
|
|
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:Body>
|
|
<ObtainUserTicket xmlns="http://www.pageflex.com/XmlWebServices/2004/StorefrontAPI/20041111">
|
|
<username>ddembinski</username>
|
|
<password>mond@y</password>
|
|
<ident>string</ident>
|
|
</ObtainUserTicket>
|
|
</soap12:Body>
|
|
</soap12:Envelope>"""
|
|
|
|
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)
|
|
temp1 = response.split('<ObtainUserTicketResult>')
|
|
temp2 = temp1[1].split('</ObtainUserTicketResult>')
|
|
ticket = temp2[0]
|
|
# print("got ticket: " + ticket)
|
|
return ticket
|
|
|
|
def Release_Ticket(ticket, URL, HOST):
|
|
ReleaseTicket = """<?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:Body>
|
|
<ReleaseTicket xmlns="http://www.pageflex.com/XmlWebServices/2004/StorefrontAPI/20041111">
|
|
<ticket>"""+ticket+""""</ticket>
|
|
</ReleaseTicket>
|
|
</soap12:Body>
|
|
</soap12:Envelope>"""
|
|
headers = {'Host': HOST, 'Content-Type': 'application/soap+xml; charset=utf-8', 'Content-Length': 'length'}
|
|
response = requests.post(url=URL, data=ReleaseTicket, headers=headers).text
|
|
# print("released ticket "+ticket)
|
|
|
|
def Run_Report(ticket, URL, HOST):
|
|
|
|
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:Body>
|
|
<GetReport xmlns="http://www.pageflex.com/XmlWebServices/2004/StorefrontAPI/20041111">
|
|
<token>"""+ticket+"""</token>
|
|
<reportName>Orders</reportName>
|
|
<columnNames>
|
|
<string>Order ID</string>
|
|
<string>Order Price</string>
|
|
</columnNames>
|
|
</GetReport>
|
|
</soap12:Body>
|
|
</soap12:Envelope>"""
|
|
|
|
headers = {'Host': HOST, 'Content-Type': 'application/soap+xml; charset=utf-8', 'Content-Length': 'length'}
|
|
response = requests.post(url=URL, data=send, headers=headers).text
|
|
# print(response)
|
|
temp1 = response.split('</GetReportResult>')
|
|
temp2 = temp1[1].split('<error />')
|
|
report = (temp2[0])
|
|
# print(report)
|
|
|
|
y = bs(report, "lxml")
|
|
results = []
|
|
|
|
with open('report.csv', mode='w') 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 = []
|
|
|
|
def loadMenu():
|
|
|
|
with open("Config_ORIG.xml") as f:
|
|
r = f.read()
|
|
|
|
y = bs(r, "lxml")
|
|
|
|
for x in y.find_all('name'):
|
|
# print(x.text)
|
|
ClientName.append(x.text)
|
|
# print(ClientName)
|
|
|
|
for x in y.find_all('storefrontapiurl'):
|
|
# print(x)
|
|
SF_URL.append(x.text)
|
|
# print(SF_URL)
|
|
|
|
for x in SF_URL:
|
|
temp1 = x.split('://')
|
|
temp2 = temp1[1].split('/')
|
|
HOST = (temp2[0])
|
|
SF_HOST.append(HOST)
|
|
# print(SF_HOST)
|
|
|
|
choice = 0
|
|
for x in ClientName:
|
|
print(choice, x)
|
|
choice = choice + 1
|
|
|
|
option = int(input())
|
|
print(SF_URL[option])
|
|
print(SF_HOST[option])
|
|
|
|
return SF_URL[option], SF_HOST[option]
|
|
|
|
def main():
|
|
loadMenu()
|
|
URL = 'http://soprema.gli.us.com/Store/storefrontapi.asmx'
|
|
HOST = 'soprema.gli.us.com'
|
|
ticket = Obtain_Ticket(URL, HOST)
|
|
Run_Report(ticket, URL, HOST)
|
|
Release_Ticket(ticket, URL, HOST)
|
|
|
|
main()
|
|
|