Mar-25-2021, 04:43 AM
Hello guys...
What's going on with my code?
It's interesting because, smetimes it works, and sometimes it doesn't.
What's going on with my code?
from tempfile import NamedTemporaryFile from FlightRadar24.api import FlightRadar24API from time import time, sleep from datetime import datetime import shutil import csv from pandas import DataFrame import re import threading import schedule import time import sched, time nav = [] n_acft_voando = [] while True: fr_api = FlightRadar24API() empresas = ['AZU', 'GLO', 'LAN'] #, 'JBU', 'AAL', 'DAL', 'ACA', 'UAL' pattern = "<(.*?)>" agora = datetime.now() dia = agora.strftime("%d/%m/%Y") hora = agora.strftime("%H:%M:%S") for i in range(0,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[0], nav[1], nav[2]] 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) sleep(60)I'm getting the following error:
Error:IndexError Traceback (most recent call last)
<ipython-input-2-aac74b35f2b2> in <module>
33 substring = substring.split(' - ')
34 modelo_tail = [x.replace(" ", ";") for x in substring]
---> 35 n_acft_voando = [dia, hora, nav[0], nav[1], nav[2]]
36 acft_voando=[dia, hora, modelo_tail[0]]
37 print(acft_voando)
IndexError: list index out of range
How can I fix it?It's interesting because, smetimes it works, and sometimes it doesn't.