Project ID printed for every task on the API problem

0 votes

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? 

Feb 2, 2023 in Others by Kithuzzz
• 38,000 points
457 views

1 answer to this question.

0 votes

Try this:

def teste(id): 
  listID = (id)# this is list of ids. Yes, that list you want this id go to the file xml. Yes, but the file today is a big one
  #print (listID)
  headers = {
        "Authorization":"xxxxxxxxxx",
        "Content-Type":"application/json;charset=UTF-8"
    } 
  
  
  #A contagem do counter começa negativa pois eu quero que a primeira busca de página seja no valor 0 > que busca as primeiras 50 tarefas
  
  length = len(listID)
  nome = []
  codigoTarefa = []
  situacaoTarefa = []
  faseNome = []
  global ID_List
  ID_List = [] #but how did u get this list became an [254,254,254,254,255,255,255 etc]

  for li in range(length):
    for count in range(4):
      #o start dentro de url é o counter. Ou seja, ele vai até 4, a partir do 0
      url = "https://xxxxxxxxx.com/api/v1/implantacao/projeto/{}/tarefa?start={}&limit=50".format(listID[li], count) #here i got the id from the code above, and count is the pagination about api
      #print(url)
      response = requests.get(url, headers=headers)
      data = response.json()

      
      unidades2(data, nome, codigoTarefa, situacaoTarefa, faseNome, listID[li])#li is legnth of  id list ok? Ok, i get it now. So )
  #print(nome)
  
  wb = openpyxl.Workbook()
  sheet = wb.active

  for i in range(len(nome)):
    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("dados12.xlsx")
  #print(codigoTarefa)
  #print(situacaoTarefa)
  #print(faseNome)
      

def unidades2(data, nome, codigoTarefa, situacaoTarefa, faseNome, ID):   # ok just wait secounds this ID here is the parameter to the above listID[li]
  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)# append here
    coluna +=1
   
  
  
 
  
if __name__ == '__main__':
  Sults()
answered Feb 2, 2023 by narikkadan
• 63,600 points

Related Questions In Others

0 votes
1 answer

Where is the documentation to refer for coinbase api integration of Etherium coin currency in php?

Hey there! Please refer to the following ...READ MORE

answered Jan 25, 2019 in Others by Omkar
• 69,220 points
843 views
0 votes
1 answer
0 votes
1 answer

Excel formula for searching two text in one cell and return values based on the result

You can include a second IF within ...READ MORE

answered Oct 10, 2022 in Others by narikkadan
• 63,600 points
1,208 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
0 votes
1 answer

Why is just an ID in the URL path a bad idea for SEO?

yes it affects the click through rates ...READ MORE

answered Feb 20, 2022 in Others by narikkadan
• 63,600 points
514 views
0 votes
1 answer

Laravel , Blade & React js add the meta tag for rendering on server side SEO

use septia laravel side rendering and add ...READ MORE

answered Feb 24, 2022 in Others by narikkadan
• 63,600 points
1,656 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP