import requests
import xlrd
from pathlib import Path
def my_xml(citype, oldname, newname):
return f'''<?xml version='1.0' encoding='UTF-8'?>
<API version='1.0' >
<citype>
<name>{citype}</name>
<criterias>
<criteria>
<parameter>
<name compOperator="IS">CI Name</name>
<value>{oldname}</value>
</parameter>
</criteria>
</criterias>
<newvalue>
<record>
<parameter>
<name>CI Name</name>
<value>{newname}</value>
</parameter>
</record>
</newvalue>
</citype>
</API>'''
if __name__ == '__main__':
datafilename = Path('data.xls')
datafilepath = Path.home() / Path('Documents/Pytest/')
datafile = datafilepath / datafilename
book = xlrd.open_workbook(datafile)
sh = book.sheet_by_index(0)
url_prefix = "http://qwerty.com/api/ci?OPERATION_NAME=update&INPUT_DATA="
for i in range(0, sh.nrows):
print(f'## Итерация номер {i} из {sh.nrows}.')
oldname = str(sh.cell_value(rowx=i, colx=0))
citype = str(sh.cell_value(rowx=i, colx=1))
newname = str(sh.cell_value(rowx=i, colx=2))
url = url_prefix + my_xml(oldname, citype, newname)
requests.post(url)