Code Monkey home page Code Monkey logo

google-flights-rs's Introduction

google-flights-rs

Unofficial API for google flights, impemented in Rust.

Limitations

The frontend uses the header x-googl-batchexecute-bgr to communicate with the backend. This parameter created deep in the JS files, which are deeply mangled with Google Closure compiler, and quite hard to follow, even while using a debugger. The parameter is dependent on the current time and the post request payload length, among other things. Missing this, the responses from the backend are not fully accurate. Contributions for the algorythm to calculate this parameter are welcome.

Use

Request for a single itinerary & offers

See Flights Example

Request Flight Graph

See Graph Example

google-flights-rs's People

Contributors

nas- avatar

Watchers

 avatar

google-flights-rs's Issues

Add better logging

Add tracing to have "connection" among error messages

use std::sync::Arc;
use tracing::{debug, error, info, span};

async fn outer_task(id: u32, param: bool) {
    let outer_span = span!(level: "info", "Workflow", id = id);
    enter!(outer_span); // Enter the outer span

    if param {
        // Spawn and await the inner tasks
        let inner_tasks = (0..4).into_iter().map(|inner_id| async move {
            let inner_span = span!(level: "info", "Task", parent: outer_span.clone(), id = inner_id);
            enter!(inner_span); // Enter the inner span with a link to the outer span

            // Simulate work and logging
            info!(target: &inner_span, "info ecc ecc ecc {} {}", id, inner_id);

            // Exit the inner span
            exit!(inner_span);
        });

        for task in inner_tasks {
            task.await;
        }
    }

    // Exit the outer span
    exit!(outer_span);
}

#[tokio::main]
async fn main() {
    // Set up tracing with a simple console writer
    tracing_subscriber::registry()
        .with(tracing_subscriber::fmt::layer().with_writer(std::io::stdout))
        .init();

    let tasks = (0..10).into_iter().map(|id| {
        let param = id % 2 == 0; // Simulate parameter logic
        outer_task(id as u32, param)
    });

    for task in tasks {
        task.await;
    }
}

Issue Title Fix error in processing outer object

Error in processing outer object!
[0][5][2]
Error { path: Path { segments: [Seq { index: 0 }, Seq { index: 5 }, Seq { index: 2 }] }, original: Error("invalid type: sequence, expected i32", line: 1, column: 39) }

Fix outer object processing

Error in processing outer object!
[0][5][1]
Error { path: Path { segments: [Seq { index: 0 }, Seq { index: 5 }, Seq { index: 1 }] }, original: Error("invalid type: null, expected i32", line: 1, column: 39) }

Error in processing inner object!

[5][7]
Error { path: Path { segments: [Seq { index: 5 }, Seq { index: 7 }] }, original: Error("invalid type: sequence, expected a string", line: 1, column: 18775) }

Handle 429 errors

Possibly send a sort of global stop to all the async functions trugh Apiclient if a 429 error is returned

Parsing responses

Ensure that all the lines of the output are parsed when parsing inner and outer objects.

Merge? the results in the same object before returning it?

Keep investigating why i receive stale prices. Maybe I just have to take the last envelope? Or maybe the price is the one of the first, and if it is in the second, then the second is valid, ecc?

Error in inner object

Error in processing inner object!
[2][0][2][0][2][1][24]
Error { path: Path { segments: [Seq { index: 2 }, Seq { index: 0 }, Seq { index: 2 }, Seq { index: 0 }, Seq { index: 2 }, Seq { index: 1 }, Seq { index: 24 }] }, original: Error("invalid type: sequence, expected a string", line: 1, column: 6315) }

Fix parsing error in inner object, offers.

Error in processing inner object!
[1][0][1][24]
Error { path: Path { segments: [Seq { index: 1 }, Seq { index: 0 }, Seq { index: 1 }, Seq { index: 24 }] }, original: Error("invalid type: null, expected a boolean", line: 1, column: 14076) }

Add method to_pretty which returns a simplified version of the object.

Coerce the Flight Response in an easier to use Object.

{
    "status_code:->
    "response: {
        best_flights:[ItineraryContainer],
        other_flights:[],
        trip_cost:Trip_cost,
        price_graph:[]
    }
}
where
ItineraryContainer:{
    flight_by: itinerary.flight_by,
    flight_details:Vec[FlightsDetails]
    departure_airport_code: itinerary.departure_airport_code
    departure_times:FlightDeparture
    departure_date_time: itinerary.departure_date + itinerary.departure_hour
    arrival_airport_code:itinerary....
    arrival_date_time: itinerary.arrival_date + itinerary.arrival_hour
    total_time_minutes:itinerary....
    cost:TripCost
    elissioms:itinerary....
    co2_lowest_route_g:itinerary....co2_lowest_route_g
}

and
FlightsDetails: {
    departure_airport_code:
    destination_airport_code:
    departure_date_time: departure_date + departure_hour
    arrival_date_time: arrival_date + arrival_hour
    legroom:
    Aircraft
    seat_type
    operated_by
    flight_number_code,

}

Error Section:

Issue Title Fix error in processing outer object

Error in processing outer object!
[0][5][2]
Error { path: Path { segments: [Seq { index: 0 }, Seq { index: 5 }, Seq { index: 2 }] }, original: Error("invalid type: sequence, expected i32", line: 1, column: 39) }

Inner object errors

Error in processing inner object!
[3][0][0][0][2][0][24]
Error { path: Path { segments: [Seq { index: 3 }, Seq { index: 0 }, Seq { index: 0 }, Seq { index: 0 }, Seq { index: 2 }, Seq { index: 0 }, Seq { index: 24 }] }, original: Error("invalid length 1, expected struct Unknown24 with 2 elements", line: 1, column: 7800) }

Error in processing inner object!
.
Error { path: Path { segments: [] }, original: Error("invalid length 15, expected struct RawResponse with 29 elements", line: 1, column: 3379) }

Implement currency

At the moment, the prices returned default of the local currency of the country where you connect from.

There is the need to check if it possible to make a request for the desired currency.

Error in processing inner object!

Error in processing inner object!
[4][0][30][0][2][0][10]
Error { path: Path { segments: [Seq { index: 4 }, Seq { index: 0 }, Seq { index: 30 }, Seq { index: 0 }, Seq { index: 2 }, Seq { index: 0 }, Seq { index: 10 }] }, original: Error("invalid length 0, expected struct Hour with 2 elements", line: 1, column: 51180) }
Error in processing inner object!
Error in processing inner object!
[6][0][4]
Error { path: Path { segments: [Seq { index: 6 }, Seq { index: 0 }, Seq { index: 4 }] }, original: Error("invalid length 1, expected struct CheaperTravelDifferentPlaces with 2 elements", line: 1, column: 2688) }

Return single structs

Return Single structs from the various API calls.

The underlying can be a vec, its fine, but the return should be a single object.

This enables having all the methods on a single object instead that scattered around.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.