diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/src/main.rs b/src/main.rs index 2bdb798..402b7c5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,6 +25,26 @@ fn main() { ); } +fn setup() -> (String, String) { + let city_id = read_file("city_id"); + let api_key = read_file("api_key"); + + let weather_url: String = format!( + "https://api.openweathermap.org/data/2.5/weather?id={}&appid={}&units=metric", + city_id, api_key + ); + let forecast_url: String = format!( + "https://api.openweathermap.org/data/2.5/forecast?id={}&appid={}&units=metric&cnt=1", + city_id, api_key + ); + (weather_url, forecast_url) +} + +fn read_file(file_name: &str) -> String { + let path = Path::new(CONFIG_PATH).join(file_name); + fs::read_to_string(path.to_string_lossy().to_string()).unwrap() +} + fn request_weather( (weather_url, forecast_url): (String, String), ) -> Result<(String, String), reqwest::Error> { @@ -89,23 +109,3 @@ fn get_trend_icon(t1: i32, t2: i32) -> char { '' } } - -fn setup() -> (String, String) { - let city_id = read_file("city_id"); - let api_key = read_file("api_key"); - - let current_url: String = format!( - "https://api.openweathermap.org/data/2.5/weather?id={}&appid={}&units=metric", - city_id, api_key - ); - let forecast_url: String = format!( - "https://api.openweathermap.org/data/2.5/forecast?id={}&appid={}&units=metric&cnt=1", - city_id, api_key - ); - (current_url, forecast_url) -} - -fn read_file(file_name: &str) -> String { - let path = Path::new(CONFIG_PATH).join(file_name); - fs::read_to_string(path.to_string_lossy().to_string()).unwrap() -} |