import requests from bs4 import BeautifulSoup as bs import csv ClientName = [] SF_URL = [] SF_HOST = [] def Obtain_Ticket(URL, HOST): GetTicket = """ ddembinski mond@y string """ 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('') temp2 = temp1[1].split('') ticket = temp2[0] # print("got ticket: " + ticket) return ticket def Release_Ticket(ticket, URL, HOST): ReleaseTicket = """ """+ticket+"""" """ 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 = """ """+ticket+""" Orders Order ID Order Price """ 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('') temp2 = temp1[1].split('') 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()