Updating naming conventions and adding fog.

This commit is contained in:
calcu1on 2025-05-02 07:57:36 -04:00
parent 6947fdec04
commit 798c305a65
3 changed files with 25 additions and 22 deletions

View File

@ -10,26 +10,28 @@ pub enum Icons {
Clear,
Cloudy,
Thunderstorms,
Fog,
}
impl Icons {
pub fn get_icon_str(&self) -> String {
pub fn icon_str(&self) -> String {
match self {
Icons::Fahrenheit => Self::get_icon("e341").unwrap().to_string(),
Icons::Clock => Self::get_icon("e641").unwrap().to_string(),
Icons::Baseball => Self::get_icon("f0852").unwrap().to_string(),
Icons::Sunny => Self::get_icon("f0599").unwrap().to_string(),
Icons::Mixed => Self::get_icon("f067f").unwrap().to_string(),
Icons::Rain => Self::get_icon("e239").unwrap().to_string(),
Icons::Snow => Self::get_icon("f0f36").unwrap().to_string(),
Icons::Clear => Self::get_icon("e30d").unwrap().to_string(),
Icons::Cloudy => Self::get_icon("e312").unwrap().to_string(),
Icons::Thunderstorms => Self::get_icon("e338").unwrap().to_string(),
Icons::Fahrenheit => Self::icon("e341").unwrap().to_string(),
Icons::Clock => Self::icon("e641").unwrap().to_string(),
Icons::Baseball => Self::icon("f0852").unwrap().to_string(),
Icons::Sunny => Self::icon("f0599").unwrap().to_string(),
Icons::Mixed => Self::icon("f067f").unwrap().to_string(),
Icons::Rain => Self::icon("e239").unwrap().to_string(),
Icons::Snow => Self::icon("f0f36").unwrap().to_string(),
Icons::Clear => Self::icon("e30d").unwrap().to_string(),
Icons::Cloudy => Self::icon("e312").unwrap().to_string(),
Icons::Thunderstorms => Self::icon("e338").unwrap().to_string(),
Icons::Fog => Self::icon("e313").unwrap().to_string(),
}
}
fn get_icon(code: &str) -> Option<char> {
fn icon(code: &str) -> Option<char> {
u32::from_str_radix(&code, 16).ok().and_then(char::from_u32)
}
}

View File

@ -29,9 +29,9 @@ fn main() {
}.get_full_forecast();
let sox_games: HashMap<String,GameInfo> = redsox::get_schedule();
// Build icons.
let baseball_icon = Icons::Baseball.get_icon_str();
let clock_icon = Icons::Clock.get_icon_str();
let fahrenheit_icon = Icons::Fahrenheit.get_icon_str();
let baseball_icon = Icons::Baseball.icon_str();
let clock_icon = Icons::Clock.icon_str();
let fahrenheit_icon = Icons::Fahrenheit.icon_str();
// Build the rows for the table.
let mut table_rows: Vec<TableRow> = vec![];
let mut game_flag = false;

View File

@ -73,15 +73,16 @@ impl WeatherOfficeLocation {
// Detect which icon to display based on short forecast.
pub fn detect_icon(short_forecast: &str) -> Option<String> {
match true {
_ if short_forecast.contains("Sunny") => Some(Icons::Sunny.get_icon_str()),
_ if short_forecast.contains("Sunny") => Some(Icons::Sunny.icon_str()),
_ if short_forecast.contains("Rain") && short_forecast.contains("Snow") => {
Some(Icons::Mixed.get_icon_str())
Some(Icons::Mixed.icon_str())
}
_ if short_forecast.contains("Thunderstorms") => Some(Icons::Thunderstorms.get_icon_str()),
_ if short_forecast.contains("Snow") => Some(Icons::Snow.get_icon_str()),
_ if short_forecast.contains("Rain") => Some(Icons::Rain.get_icon_str()),
_ if short_forecast.contains("Cloudy") => Some(Icons::Cloudy.get_icon_str()),
_ if short_forecast.contains("Clear") => Some(Icons::Clear.get_icon_str()),
_ if short_forecast.contains("Thunderstorms") => Some(Icons::Thunderstorms.icon_str()),
_ if short_forecast.contains("Snow") => Some(Icons::Snow.icon_str()),
_ if short_forecast.contains("Rain") => Some(Icons::Rain.icon_str()),
_ if short_forecast.contains("Cloudy") => Some(Icons::Cloudy.icon_str()),
_ if short_forecast.contains("Clear") => Some(Icons::Clear.icon_str()),
_ if short_forecast.contains("Fog") => Some(Icons::Fog.icon_str()),
_ => None,
}
}