diff options
author | Mustafa Salih <37256744+MustafaSalih1993@users.noreply.github.com> | 2021-01-14 05:43:01 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-14 05:43:01 +0300 |
commit | e38859e0f0106b60f2dd6d2f8260ea16e5417a96 (patch) | |
tree | acdd23279a8fc837fa076739933b1269d74110fd /src/utils/weather.rs | |
parent | e829871f2d757c7414763992839a584038c7b443 (diff) | |
parent | 6a349a0e0282e56b03adbe02b41bfaf0cc3213f1 (diff) |
Merge pull request #34 from MustafaSalih1993/dev
orginized the code to seprated mods and deleted the lib file
Diffstat (limited to 'src/utils/weather.rs')
-rw-r--r-- | src/utils/weather.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/utils/weather.rs b/src/utils/weather.rs new file mode 100644 index 0000000..05fa60b --- /dev/null +++ b/src/utils/weather.rs @@ -0,0 +1,22 @@ +use crate::types::Config; + +// will make a GET request from wttr.in +pub fn get_weather(config: &Config) -> String { + let format = if config.weather.format.is_empty() { + String::from("%l:+%t") + } else { + config.weather.format.clone() + }; + + let url = format!("http://wttr.in/{}?format=\"{}", config.weather.city, format); + let err_string = String::from("Error"); + let res = match minreq::get(url).send() { + Ok(resp) => match resp.as_str() { + Ok(res_str) => res_str.trim_matches('"').to_string(), + Err(_) => err_string, + }, + Err(_) => err_string, + }; + + format!(" {} {} {}", config.weather.icon, res, config.seperator) +} |