From 5406651b29e3db786f31588e4fe91a8a40bf195f Mon Sep 17 00:00:00 2001 From: Adam <56338480+adastx@users.noreply.github.com> Date: Mon, 25 Jul 2022 18:44:17 +0200 Subject: Minor refactor --- src/main.rs | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'src') 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() -} -- cgit v1.2.3-70-g09d2