I've got some code that asks an API down below. The url runs four times for each ID in the listID. In this case, the url will be as follows: https://xxxxapi/v1/implantacao/projeto/1/tarefa?start=0&limit=50, then https://xxxxapi/v1/implantacao/projeto/1/tarefa?start=1&limit=50, and so on, where start ranges from 0 to 3 for each listID.
Then, everything works perfectly when I save every data request I receive in an xls file. For instance, 120 jobs are typically returned after 4 loops at the id. For each job that the code produces, I want to output the ID in the following line: #sheet.cell(row=i+1, column=1). worth = listID
def teste(id):
listID = (id)
headers = {
"xxxxxxxxx",
"Content-Type":"application/json;charset=UTF-8"
}
length = len(listID)
nome = []
codigoTarefa = []
situacaoTarefa = []
faseNome = []
for li in range(length):
for count in range(4):
url = "https://xxxxapi/v1/implantacao/projeto/{}/tarefa?start={}&limit=50".format(listID[li], count)
response = requests.get(url, headers=headers)
data = response.json()
unidades2(data, nome, codigoTarefa, situacaoTarefa, faseNome)
wb = openpyxl.Workbook()
sheet = wb.active
for i in range(len(nome)):
#sheet.cell(row=i+1, column=1).value = listID
sheet.cell(row=i+1, column=2).value = nome[i]
sheet.cell(row=i+1, column=3).value = codigoTarefa[i]
sheet.cell(row=i+1, column=4).value = situacaoTarefa[i]
wb.save("dados11.xlsx")
def unidades2(data, nome, codigoTarefa, situacaoTarefa, faseNome):
workbook = xlwt.Workbook()
sheet = workbook.add_sheet("BACKOFFICE")
coluna = 1
for i in data['data']:
nome.append(i['nome'])
codigoTarefa.append(i['codigo'])
situacaoTarefa.append(i['situacao'])
coluna +=1
if __name__ == '__main__':
Sults()
To be more clear: One output example from one task at project ID 1 :
INAUGURAÇÃO T98 4
I want this output (1 is the first item in listID for example) : 1 INAUGURAÇÃO T98 4
How can I get it?