Skip to content

Add flight tracking module #64

@ju135

Description

@ju135

The bot should be able to track flights based on their flight number.

Example command:

/flight DY611

The bot should then update the chat for information about this flight. E.g. send a message when the flight departs / arrives.
Might also make sense to tag the passenger, like:

/flight DY611 @heinz

This could result in messages like:

  • DY611 from Vienna to Oslo will depart in 5 minutes. Have a pleasant flight @heinz!
  • @heinz just arrived in Oslo 🎉

flightradar24 might be a good API to retrieve flight information.

Here's a code snippet to retrieve the next upcoming flight data of a given flight id:

import flightradar24
import time

flight_id = 'DY1632'  # Turkish Airlines' Istanbul - New York flight
fr = flightradar24.Api()
flight = fr.get_flight(flight_id)

if 'result' in flight and 'response' in flight['result']:
    response = flight['result']['response']

    upcoming_flight = None
    current_timestamp = time.time()
    for item in response['data']:
        departure_time = item['time']['scheduled']['departure']
        if departure_time > current_timestamp:
            if upcoming_flight is None or departure_time < upcoming_flight['time']['scheduled']['departure']:
                upcoming_flight = item

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions