aboutsummaryrefslogtreecommitdiff
path: root/src/utils/weather.rs
blob: 05fa60bc25d6d58c831d7ea550934edfd31facf8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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)
}