clean code
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
nyyu 2021-03-15 07:56:07 +01:00
parent 1c0dbb7bba
commit 0db7d4f990

View file

@ -57,7 +57,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok(x) => x, Ok(x) => x,
Err(_e) => PathBuf::from(LOL_CHAMPS_DIR), Err(_e) => PathBuf::from(LOL_CHAMPS_DIR),
}; };
info!("LoL Champs Folder: {}", lol_champs_dir.to_str().unwrap_or(LOL_CHAMPS_DIR)); info!(
"LoL Champs Folder: {}",
lol_champs_dir.to_str().unwrap_or(LOL_CHAMPS_DIR)
);
let client = ureq::AgentBuilder::new() let client = ureq::AgentBuilder::new()
.timeout(Duration::from_secs(10)) .timeout(Duration::from_secs(10))
@ -97,28 +100,25 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
); );
for (id, positions) in &champs { for (id, positions) in &champs {
let mut champ_id: String = id.to_owned(); let mut champ_id = id.to_owned();
if !champion.data.contains_key(&champ_id) { if !champion.data.contains_key(&champ_id) {
champ_id = get_champ_from_key(&champion, &champ_id); if let Some(c_id) = get_champ_from_key(&champion, &champ_id) {
champ_id = c_id;
}
} }
if champion.data.contains_key(&champ_id) { if let Some(champ) = champion.data.get(&champ_id) {
let path = lol_champs_dir.join(&champ_id).join("Recommended");
fs::create_dir_all(&path).unwrap();
if positions.is_empty() { if positions.is_empty() {
error!("{} missing positions", &champ_id); error!("{} missing positions", &champ_id);
} } else {
let path = lol_champs_dir.join(&champ_id).join("Recommended");
fs::create_dir_all(&path)?;
for pos in positions { for pos in positions {
data_source.write_item_set( data_source.write_item_set(&champ, &pos, &patch, &path, &client);
&champion.data.get(&champ_id).unwrap(),
&pos,
&patch,
&path,
&client,
);
thread::sleep(Duration::from_millis(data_source.get_timeout())); thread::sleep(Duration::from_millis(data_source.get_timeout()));
} }
}
} else { } else {
error!("{} not found in LoL champs", &champ_id); error!("{} not found in LoL champs", &champ_id);
} }
@ -127,13 +127,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok(()) Ok(())
} }
fn get_champ_from_key(champs: &Champion, key: &str) -> String { fn get_champ_from_key(champs: &Champion, key: &str) -> Option<String> {
for champ in champs.data.values() { for champ in champs.data.values() {
if key == champ.key { if key == champ.key {
return champ.id.to_owned(); return Some(champ.id.to_owned());
} }
} }
String::new() None
} }
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]