2020-12-23 01:17:21 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate tracing;
|
|
|
|
|
|
|
|
use color_eyre::eyre::Result;
|
|
|
|
use encoding_rs::WINDOWS_1252;
|
|
|
|
use encoding_rs_io::DecodeReaderBytesBuilder;
|
|
|
|
use serde_xml_rs::from_reader;
|
|
|
|
|
|
|
|
use mi::*;
|
|
|
|
|
|
|
|
pub const WEATHER_URL: &'static str =
|
|
|
|
"https://dd.weather.gc.ca/citypage_weather/xml/QC/s0000635_e.xml";
|
|
|
|
|
|
|
|
fn main() -> Result<()> {
|
|
|
|
color_eyre::install()?;
|
|
|
|
tracing_subscriber::fmt::init();
|
|
|
|
|
|
|
|
info!("{} weather importer starting up", mi::APPLICATION_NAME);
|
|
|
|
|
2021-01-10 16:41:26 +00:00
|
|
|
let resp = ureq::get(WEATHER_URL)
|
|
|
|
.set("User-Agent", WEATHER_URL)
|
|
|
|
.call()
|
|
|
|
.map_err(|why| {
|
|
|
|
panic!("{}", why.to_string());
|
|
|
|
why
|
|
|
|
})?;
|
2020-12-23 01:17:21 +00:00
|
|
|
|
|
|
|
let fin = DecodeReaderBytesBuilder::new()
|
|
|
|
.encoding(Some(WINDOWS_1252))
|
|
|
|
.build(resp.into_reader());
|
2020-12-23 22:43:11 +00:00
|
|
|
let data: web::canada_weather::types::SiteData = from_reader(fin)?;
|
|
|
|
let data: web::canada_weather::Report = data.into();
|
2020-12-23 01:17:21 +00:00
|
|
|
|
2020-12-23 22:43:11 +00:00
|
|
|
println!("{}", serde_json::to_string_pretty(&data)?);
|
2020-12-23 01:17:21 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|