Mar-25-2021, 01:42 PM
Don't call this:
What does this line do?
Why does in need nav[0], nave[1] and nav[2]? What are nav[0], nav[1] and nav[2]?
I find it suspicious that these indices are hard coded when the outer loop may run more than 3 times based on this:
n_acft_voando = [dia, hora, nav[0], nav[1], nav[2]]Until you've done this three times:
for i in range(0,len(empresas)): nav.append(len(fr_api.get_flights(airline = empresas[i])))It is difficult to say how such a thing is accomplished since it depends as much on what the program does as the nuts and bolts of coding the program so it doesn't crash. Right now all I have to work with is some code that doesn't work. it is difficult to know how to fix it unless I know what it is SUPPOSED to do.
What does this line do?
n_acft_voando = [dia, hora, nav[0], nav[1], nav[2]][/python]
Why does in need nav[0], nave[1] and nav[2]? What are nav[0], nav[1] and nav[2]?
I find it suspicious that these indices are hard coded when the outer loop may run more than 3 times based on this:
empresas = ['AZU', 'GLO', 'LAN'] #, 'JBU', 'AAL', 'DAL', 'ACA', 'UAL'Is this a hint that empresas may be a larger list?. If so, maybe the proper way to code this is:
for i in range(2): nav.append(len(fr_api.get_flights(airline = empresas[i]))) for i in range(2,len(empresas)): nav.append(len(fr_api.get_flights(airline = empresas[i]))) dados_voo = fr_api.get_flights(airline = empresas[i]) for k in range (0,len(dados_voo)): substring = re.search(pattern, str(dados_voo[k])).group(1) substring = substring.split(' - ') modelo_tail = [x.replace(" ", ";") for x in substring] n_acft_voando = [dia, hora, nav[i-2], nav[i-1], nav[i]] acft_voando=[dia, hora, modelo_tail[0]] print(acft_voando) with open(r'C:\Users\bruno\Desktop\Voos\DB\AeronavesAr.txt', 'a', newline='') as f: writer = csv.writer(f, delimiter=';') writer.writerow(n_acft_voando) with open(r'C:\Users\bruno\Desktop\Voos\DB\DetalhesAeronaves.txt', 'a', newline='') as f: writer = csv.writer(f, delimiter=';') writer.writerow(acft_voando)Again, I don't know if this is correct.