rte-france-rs/examples/static.rs

41 lines
8.9 KiB
Rust
Raw Normal View History

use rte_france::api::consumption::ConsumptionForecast;
use rte_france::api::consumption::ShortTermForecastType;
struct CachedApi {}
impl rte_france::ApiClient for CachedApi {
fn http_get(
&self,
_path: &str,
_query_string: &[(String, String)],
) -> std::result::Result<std::string::String, anyhow::Error> {
// Simulated JSON data
let _json_data = r#"{"short_term":[{"type":"D-2","start_date":"2024-10-24T00:00:00+02:00","end_date":"2024-10-25T00:00:00+02:00","values":[{"start_date":"2024-10-24T00:00:00+02:00","end_date":"2024-10-24T00:30:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":46147},{"start_date":"2024-10-24T00:30:00+02:00","end_date":"2024-10-24T01:00:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":44347},{"start_date":"2024-10-24T01:00:00+02:00","end_date":"2024-10-24T01:30:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":42455},{"start_date":"2024-10-24T01:30:00+02:00","end_date":"2024-10-24T02:00:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":42743},{"start_date":"2024-10-24T02:00:00+02:00","end_date":"2024-10-24T02:30:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":42241},{"start_date":"2024-10-24T02:30:00+02:00","end_date":"2024-10-24T03:00:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":40843},{"start_date":"2024-10-24T03:00:00+02:00","end_date":"2024-10-24T03:30:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":39721},{"start_date":"2024-10-24T03:30:00+02:00","end_date":"2024-10-24T04:00:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":39013},{"start_date":"2024-10-24T04:00:00+02:00","end_date":"2024-10-24T04:30:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":38209},{"start_date":"2024-10-24T04:30:00+02:00","end_date":"2024-10-24T05:00:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":37957},{"start_date":"2024-10-24T05:00:00+02:00","end_date":"2024-10-24T05:30:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":38579},{"start_date":"2024-10-24T05:30:00+02:00","end_date":"2024-10-24T06:00:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":40050},{"start_date":"2024-10-24T06:00:00+02:00","end_date":"2024-10-24T06:30:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":41790},{"start_date":"2024-10-24T06:30:00+02:00","end_date":"2024-10-24T07:00:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":44556},{"start_date":"2024-10-24T07:00:00+02:00","end_date":"2024-10-24T07:30:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":47725},{"start_date":"2024-10-24T07:30:00+02:00","end_date":"2024-10-24T08:00:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":50286},{"start_date":"2024-10-24T08:00:00+02:00","end_date":"2024-10-24T08:30:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":51826},{"start_date":"2024-10-24T08:30:00+02:00","end_date":"2024-10-24T09:00:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":52039},{"start_date":"2024-10-24T09:00:00+02:00","end_date":"2024-10-24T09:30:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":52375},{"start_date":"2024-10-24T09:30:00+02:00","end_date":"2024-10-24T10:00:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":52879},{"start_date":"2024-10-24T10:00:00+02:00","end_date":"2024-10-24T10:30:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":52800},{"start_date":"2024-10-24T10:30:00+02:00","end_date":"2024-10-24T11:00:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":52910},{"start_date":"2024-10-24T11:00:00+02:00","end_date":"2024-10-24T11:30:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":52874},{"start_date":"2024-10-24T11:30:00+02:00","end_date":"2024-10-24T12:00:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":53051},{"start_date":"2024-10-24T12:00:00+02:00","end_date":"2024-10-24T12:30:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":53696},{"start_date":"2024-10-24T12:30:00+02:00","end_date":"2024-10-24T13:00:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":52632},{"start_date":"2024-10-24T13:00:00+02:00","end_date":"2024-10-24T13:30:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":53547},{"start_date":"2024-10-24T13:30:00+02:00","end_date":"2024-10-24T14:00:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":51565},{"start_date":"2024-10-24T14:00:00+02:00","end_date":"20
let _json_data = r#"{"short_term":[{"type":"D-2","start_date":"2024-10-24T00:00:00+02:00","end_date":"2024-10-25T00:00:00+02:00","values":[{"start_date":"2024-10-24T00:00:00+02:00","end_date":"2024-10-24T00:30:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":46147},{"start_date":"2024-10-24T00:30:00+02:00","end_date":"2024-10-24T01:00:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":44347},{"start_date":"2024-10-24T01:00:00+02:00","end_date":"2024-10-24T01:30:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":42455},{"start_date":"2024-10-24T01:30:00+02:00","end_date":"2024-10-24T02:00:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":42743},{"start_date":"2024-10-24T02:00:00+02:00","end_date":"2024-10-24T02:30:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":42241}]}]}"#;
let json_data = r#"{"short_term":[{"type":"D-2","start_date":"2024-10-24T00:00:00+02:00","end_date":"2024-10-25T00:00:00+02:00","values":[{"start_date":"2024-10-24T00:00:00+02:00","end_date":"2024-10-24T00:30:00+02:00","updated_date":"2024-10-23T00:21:44+02:00","value":46147}]}]}"#;
// Return the fake response as Ok
Ok(json_data.to_string())
}
}
fn main() {
/*
let client_id = std::env::var("CLIENT_ID").expect("CLIENT_ID must be set");
let client_secret = std::env::var("CLIENT_SECRET").expect("CLIENT_SECRET must be set");
let mut rte_api = RteApi::new(client_id, client_secret);
println!("rte_api: {:?}", rte_api);
rte_api.authenticate().expect("Failed to authenticate");
*/
let rte_api = CachedApi {};
println!("Will gen cf");
let consumption_forecast = ConsumptionForecast::new(&rte_api);
println!("Will gen data");
let data = consumption_forecast.short_term(ShortTermForecastType::DayAfterTomorrow, None);
println!("data: {:?}", data);
println!("{}", data.unwrap().as_polars_df().unwrap());
}