Updated to allow updating URL/Hostname easier.

This commit is contained in:
2019-06-03 21:40:50 -04:00
parent ac6f077879
commit cfa93e0092

28
main.py
View File

@@ -1,7 +1,7 @@
import requests import requests
from lxml import etree from lxml import etree
def Obtain_Ticket(): 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">
<soap12:Body> <soap12:Body>
@@ -13,15 +13,16 @@ def Obtain_Ticket():
</soap12:Body> </soap12:Body>
</soap12:Envelope>""" </soap12:Envelope>"""
headers = {'Host': 'soprema.gli.us.com', '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('http://soprema.gli.us.com/Store/storefrontapi.asmx', data=GetTicket, headers=headers).text response = requests.post(url=URL, data=GetTicket, headers=headers).text
# print(response)
temp1 = response.split('<ObtainUserTicketResult>') temp1 = response.split('<ObtainUserTicketResult>')
temp2 = temp1[1].split('</ObtainUserTicketResult>') temp2 = temp1[1].split('</ObtainUserTicketResult>')
ticket = temp2[0] ticket = temp2[0]
# print("got ticket: " + ticket) # print("got ticket: " + ticket)
return ticket return ticket
def Release_Ticket(ticket): def Release_Ticket(ticket, URL, HOST):
ReleaseTicket = """<?xml version="1.0" encoding="utf-8"?> 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: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>
@@ -30,12 +31,11 @@ def Release_Ticket(ticket):
</ReleaseTicket> </ReleaseTicket>
</soap12:Body> </soap12:Body>
</soap12:Envelope>""" </soap12:Envelope>"""
headers = {'Host': 'soprema.gli.us.com', '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=ReleaseTicket, headers=headers).text
response = requests.post('http://soprema.gli.us.com/Store/storefrontapi.asmx', data=ReleaseTicket, headers=headers).text
# print("released ticket "+ticket) # print("released ticket "+ticket)
def Run_Report(ticket): def Run_Report(ticket, URL, HOST):
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">
@@ -51,14 +51,16 @@ def Run_Report(ticket):
</soap12:Body> </soap12:Body>
</soap12:Envelope>""" </soap12:Envelope>"""
headers = {'Host': 'soprema.gli.us.com', '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('http://soprema.gli.us.com/Store/storefrontapi.asmx', data=send, headers=headers).text response = requests.post(url=URL, data=send, headers=headers).text
print(response) print(response)
def main(): def main():
ticket = Obtain_Ticket() URL = 'http://soprema.gli.us.com/Store/storefrontapi.asmx'
Run_Report(ticket) HOST = 'soprema.gli.us.com'
Release_Ticket(ticket) ticket = Obtain_Ticket(URL, HOST)
Run_Report(ticket, URL, HOST)
Release_Ticket(ticket, URL, HOST)
main() main()