summaryrefslogtreecommitdiff
path: root/src/parser.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser.rs')
-rw-r--r--src/parser.rs25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/parser.rs b/src/parser.rs
index 6a5166d..8e17682 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -133,7 +133,7 @@ pub fn determine_weather_type(temp: f32, humidity: Option<u32>) -> &'static str
}
/// Arts loader with exception wrappers
-fn load_arts() -> Result<ArtsData, Box<dyn std::error::Error>> {
+fn load_arts(debug: bool) -> Result<ArtsData, Box<dyn std::error::Error>> {
let home = std::env::var("HOME")?;
let arts_path = format!("{}/.config/WeatherFetch/arts.yaml", home);
@@ -151,7 +151,10 @@ fn load_arts() -> Result<ArtsData, Box<dyn std::error::Error>> {
});
}
};
- println!("--- RAW FILE CONTENT START ---\n{}\n--- RAW FILE CONTENT END ---", content);
+
+ if debug == true {
+ println!("--- RAW FILE CONTENT START ---\n{}\n--- RAW FILE CONTENT END ---", content);
+ }
let arts: Arts = serde_yml::from_str(&content)?;
Ok(arts.arts)
@@ -172,7 +175,7 @@ fn process_placeholders(art: &str) -> String {
/// let data: WeatherData = parse_cached()?;
/// prepare_art(&data);
pub fn prepare_art(weather_data: &WeatherData, debug: bool) -> Result<String, Box<dyn std::error::Error>> {
- let arts = load_arts()?;
+ let arts = load_arts(debug)?;
let weather_type = determine_weather_type(
weather_data.current.temperature_2m,
@@ -186,20 +189,20 @@ pub fn prepare_art(weather_data: &WeatherData, debug: bool) -> Result<String, Bo
_ => &arts.sun,
};
- if(debug == true) {
+ if debug == true {
println!("-- RAW SELECTED ART (debug):\n{:?}\n", selected_art);
println!("-- RAW SELECTED ART (display):\n{}\n", selected_art);
}
let processed_art = process_placeholders(selected_art);
- if(debug == true) {
- println!("-- PROCESSED ART (debug):\n{:?}\n", processed_art);
- println!("-- PROCESSED ART (display):");
- println!("contains <Yellow>? {}", selected_art.contains("<Yellow>"));
- println!("contains <Purple>? {}", selected_art.contains("<Purple>"));
- println!("contains <Blue>? {}", selected_art.contains("<Blue>"));
- println!("processed contains \\x1b? {}", processed_art.contains("\x1b"));
+ if debug == true {
+ println!("-- PROCESSED ART (debug):\n{:?}\n", processed_art);
+ println!("-- PROCESSED ART (display):");
+ println!("contains <Yellow>? {}", selected_art.contains("<Yellow>"));
+ println!("contains <Purple>? {}", selected_art.contains("<Purple>"));
+ println!("contains <Blue>? {}", selected_art.contains("<Blue>"));
+ println!("processed contains \\x1b? {}", processed_art.contains("\x1b"));
}
Ok(processed_art)
}