Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flight tracking module #64

Open
ju135 opened this issue Sep 29, 2022 · 0 comments
Open

Add flight tracking module #64

ju135 opened this issue Sep 29, 2022 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@ju135
Copy link
Owner

ju135 commented Sep 29, 2022

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
@ju135 ju135 added enhancement New feature or request good first issue Good for newcomers labels Sep 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant