JeanExtreme002 / FlightRadarAPI

:airplane: Unofficial SDK for FlightRadar24 for Python 3 and NodeJS
https://pypi.org/project/FlightRadarAPI/
MIT License
286 stars 62 forks source link

My code is not working with getAirlineLogo method in nodejs (404 not found error) #57

Closed ptesny closed 8 months ago

ptesny commented 8 months ago

Describe the bug getAirlineLogo does not work in nodejs, for instance

          iata =  'CDG';
          icao =  'LFPG';
          try { const airlineLogo = await frApi.getAirlineLogo(iata, icao); return airlineLogo; }
          catch (error) { console.log(error); return error.message; }
Received status code '404: Not Found' for the URL https://www.flightradar24.com/static/images/data/operators/LFPG_logo0.png
JeanExtreme002 commented 8 months ago

I searched for the IATA and ICAO you are using, and they correspond to the code of the Paris Charles de Gaulle Airport. The method should received the IATA and ICAO of an airline. See the example bellow:

const { FlightRadar24API } = require("flightradarapi");
const fs = require("fs");

const frApi = new FlightRadar24API();

async function run() { 
    const result = await frApi.getAirlineLogo("G3", "GLO");  // GOL Airline
    const data = Buffer.from(result[0]);

    const filename = "image." + result[1];

    fs.writeFile(filename, data, (err) => {
      if (err) {
        console.error(err);
      }
    });
} 
run();
ptesny commented 8 months ago

Thank you @JeanExtreme002 for spotting this. Indeed, the code and ICAO must be those of an airline and not of an airport. All good.

PS. I prefer to return the base64 encoded image in the payload. Good to know the second element of the airlineLogo array is the image format, namely png, jpg, etc.

          code = urlParams.has('code') ? urlParams.get('code') : 'AF';
          icao = urlParams.has('icao') ? urlParams.get('icao') : 'AFR';
          try { 
            const airlineLogo = await frApi.getAirlineLogo(code, icao);
            const data = Buffer.from(airlineLogo[0]);

            return 'data:image/' + airlineLogo[1] + ';base64,' + data.toString('base64');