Miscellaneous cleanup
This commit is contained in:
parent
c3efab7b2a
commit
9954dd0b62
24
src/main.rs
24
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,
|
||||
},
|
||||
//},
|
||||
};
|
||||
|
||||
app.run();
|
||||
|
Loading…
Reference in New Issue
Block a user