Adding automatic IP address, some refactor and better texts. Upgrading version.

This commit is contained in:
2023-05-23 01:17:03 +02:00
parent 3bd55576ce
commit 01ac2ca7b7
12 changed files with 496 additions and 149 deletions
+12
View File
@@ -0,0 +1,12 @@
use crate::{coords::Coordinates, current_weather::CurrentWeather};
pub fn request_current_weather(coords: &Coordinates) -> Result<CurrentWeather, ureq::Error> {
let url = format!(
"https://api.open-meteo.com/v1/forecast?latitude={}&longitude={}&current_weather=true",
coords.latitude, coords.longitude
);
let mut body: serde_json::Value = ureq::get(&url).call()?.into_json()?;
let current_weather = body["current_weather"].take();
let current_weather: CurrentWeather = serde_json::from_value(current_weather).unwrap();
Ok(current_weather)
}