Can now generate CSV output from report. Working on reading in XML config file and setting client settings with simple menu selection
This commit is contained in:
2320
Config_ORIG.xml
Normal file
2320
Config_ORIG.xml
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
62
main.py
62
main.py
@@ -1,5 +1,12 @@
|
|||||||
import requests
|
import requests
|
||||||
from lxml import etree
|
from bs4 import BeautifulSoup as bs
|
||||||
|
import csv
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ClientName = []
|
||||||
|
SF_URL = []
|
||||||
|
SF_HOST = []
|
||||||
|
|
||||||
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"?>
|
||||||
@@ -53,9 +60,60 @@ def Run_Report(ticket, URL, HOST):
|
|||||||
|
|
||||||
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
|
||||||
print(response)
|
# 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():
|
def main():
|
||||||
|
loadMenu()
|
||||||
URL = 'http://soprema.gli.us.com/Store/storefrontapi.asmx'
|
URL = 'http://soprema.gli.us.com/Store/storefrontapi.asmx'
|
||||||
HOST = 'soprema.gli.us.com'
|
HOST = 'soprema.gli.us.com'
|
||||||
ticket = Obtain_Ticket(URL, HOST)
|
ticket = Obtain_Ticket(URL, HOST)
|
||||||
|
|||||||
Reference in New Issue
Block a user