Public
Edited
Feb 20, 2024
Insert cell
Insert cell
data = {
const flights = await getFlights([{start: timeToUnix("2023-12-10"), end: timeToUnix("2024-01-02")}], swiftOldJet)

return flights
}
Insert cell
data.filter(d => d.status === 'fulfilled' && d.value?.length !== 0).map(d => d.value.map(x => ({
celeb: 'swift',
departure: x.estDepartureAirport,
arrival: x.estArrivalAirport,
}) ) ).flat(2)
Insert cell
// return flights.map((d, i) => d.map(x => {
// return {celeb: 'swift', departure: x.estDepartureAirport, arrival: x.estArrivalAirport, month: i + 1}
// }) ).flat(2)
Insert cell
async function getFlights(dates, plane) {
try {
const flightPromises = dates.map(async d => {
const response = await fetch(`${baseURL}icao24=${plane}&begin=${d.start}&end=${d.end}`);
return response.json();
});

const flights = await Promise.allSettled(flightPromises);

return flights
} catch (error) {
console.error('Error fetching flights:', error);
throw error;
}
}
Insert cell
tSwiftPlane = 'a81b13'
Insert cell
swiftOldJet = 'ac64c6'
Insert cell
elonJet = 'a835af'
Insert cell
baseURL = 'https://opensky-network.org/api/flights/aircraft?'
Insert cell
unixDates = dates.map(d => ({start: timeToUnix(d.start), end: timeToUnix(d.end)}))
Insert cell
Insert cell

// '2012.08.10'
timeToUnix = (date) => Math.floor(new Date(date).getTime() / 1000)

Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more