Home > database >  project ID printed for every task on the API problem
project ID printed for every task on the API problem

Time:02-02

I have this code below, requesting an api. Every ID in listID loops 4 times in the url. So if the listID = [1,2,3,4,5], the url will be :
url = "https://xxxxapi/v1/implantacao/projeto/1/tarefa?start=0&limit=50" then url = "https://xxxxapi/v1/implantacao/projeto/1/tarefa?start=1&limit=50" and etc, start goes 0 to 3 for every id in the list

Then, im saving every data request i get into and xls file and that's working fine. For example, every 4 loops at the id, normally returns 120 tasks. I want to print the ID for every task that the code returns, in the line : #sheet.cell(row=i 1, column=1).value = 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 ? Thanks for the help btw

CodePudding user response:

This will probably work because every four name elements you have, you have one listID.

sheet.cell(row=i 1, column=1).value = listID[i/4]

CodePudding user response:

i dont know what you mean but try this or explain more

def teste(id): 
      listID = (id)
      headers = {
            "xxxxxxxxx",
            "Content-Type":"application/json;charset=UTF-8"
        } 
      
      length = len(listID)
      nome = []
      codigoTarefa = []
      situacaoTarefa = []
      faseNome = []
      ID_List = []
      
      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, listID[li])
      
      
      wb = openpyxl.Workbook()
      sheet = wb.active
      loop_counter = -1
      for i in range(len(nome)):
        loop_counter  =1
        sheet.cell(row=i 1, column=1).value = ID_List[i]
        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, ID):
      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'])
        ID_List.append(ID)

        coluna  =1
        
       
      
      
     
      
    if __name__ == '__main__':
      Sults() 
  • Related