Mar-31-2021, 08:44 PM
(Mar-31-2021, 08:21 PM)jefsummers Wrote: Depends on the structure of the data. This does look pretty clear, what are you looking for?
I would like to add it in my code and export the information to a TXT file.
this is the code i'm currenty running
import csv import time import sched, time from datetime import datetime from FlightRadar24.api import FlightRadar24API fr_api = FlightRadar24API() empresas = ['JES', 'DAP', 'GLO', 'THT', 'BWA'] while True: try: now = datetime.now() day = datetime.today() current_time = now.strftime("%H:%M") current_day = day.strftime("%d/%m/%y") for i in range(0,len(empresas)): flights = fr_api.get_flights(airline = empresas[i]) #print(type(flights[0])) #print(flights[0].__dict__) print("Dados da empresa: ", empresas[i], " atualizado as: ", current_time) with open(r'C:\Users\bruno\Desktop\Voos\DB\Voos.txt', 'a', newline='') as f: fieldnames = ['dia_analisado', 'hora_analisada', 'data', 'hora', 'airline_icao', 'callsign', 'aircraft_code', 'registration', 'origin_aiport_iata', 'destination_airport_iata', 'latitude', 'longitude', 'heading', 'altitude', 'ground_speed', 'on_ground', 'vertical_speed', 'squawk' ] # you can include whatever attributes you want wrtr = csv.DictWriter(f, fieldnames=fieldnames, extrasaction='ignore', delimiter=';') #wrtr.writeheader() for flight in flights: flight.data = datetime.fromtimestamp(flight.time).strftime("%d/%m/%y") # convert the timestamp to datetime object flight.hora = datetime.fromtimestamp(flight.time).strftime("%H:%M:%S") flight.hora_analisada = current_time flight.dia_analisado = current_day wrtr.writerow(flight.__dict__) # here I pass all attributes as dict, but you can always access individual attributes, like I did with time above time.sleep(60) except: print('Olha deu erro, mas vou tentar novamente!') time.sleep(10)