From 9954dd0b62a6ae35ffd21387b637c1d81a997f70 Mon Sep 17 00:00:00 2001 From: Mahesh Asolkar Date: Sat, 9 Mar 2024 14:12:08 -0800 Subject: [PATCH] Miscellaneous cleanup --- src/main.rs | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/src/main.rs b/src/main.rs index 204e691..947c634 100644 --- a/src/main.rs +++ b/src/main.rs @@ -61,35 +61,35 @@ impl BarWeather { fn get_weather(self) { // Print a web page onto stdout - let mut easy = Easy::new(); - let app = self; + let mut curl = Easy::new(); let url_string_1 :String = "https://api.weather.gov/stations/".to_owned(); - let url_string_2 :&str = app.opts.station.as_str(); + let url_string_2 :&str = self.opts.station.as_str(); let url_string_3 :String = "/observations?limit=1".to_owned(); + let url_string = url_string_1 + url_string_2 + &url_string_3; - easy.url(url_string.as_str()).unwrap(); + + curl.url(url_string.as_str()).unwrap(); let mut list = List::new(); list.append("User-Agent: Bar Weather (mahesh@heshapps.com)").unwrap(); - easy.http_headers(list).unwrap(); + curl.http_headers(list).unwrap(); - easy.write_function(move |data| { + curl.write_function(move |data| { // To debug returned JSON // use std::io::{stdout, Write}; // stdout().write_all(data).unwrap(); let v: Value = serde_json::from_str(str::from_utf8(data).unwrap()).unwrap(); - let temperature_value :f32 = app.get_current_temperature(v); - let temperature_unit :String = app.get_temperature_unit(); + let temperature_value :f32 = self.get_current_temperature(v); + let temperature_unit :String = self.get_temperature_unit(); - println!("{}{}", temperature_value, temperature_unit); println!("{:.2}{}", temperature_value, temperature_unit); Ok(data.len()) } ).unwrap(); - easy.perform().unwrap(); + curl.perform().unwrap(); } fn check_options(&self) -> bool { @@ -123,15 +123,11 @@ impl BarWeather { fn main() { let cmd_args = CommandlineArgs::parse(); let app = BarWeather { - //acts: BarWeatherActions { - opts: AppOptions { - // units: TemperatureUnits::Imperial, - // units: TemperatureUnits::Metric, - units: if cmd_args.metric { TemperatureUnits::Metric } - else { TemperatureUnits::Imperial }, - station: cmd_args.station, - }, - //}, + opts: AppOptions { + units: if cmd_args.metric { TemperatureUnits::Metric } + else { TemperatureUnits::Imperial }, + station: cmd_args.station, + }, }; app.run();