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,
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()
.timeout(Duration::from_secs(10))
@ -97,27 +100,24 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
);
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) {
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) {
let path = lol_champs_dir.join(&champ_id).join("Recommended");
fs::create_dir_all(&path).unwrap();
if let Some(champ) = champion.data.get(&champ_id) {
if positions.is_empty() {
error!("{} missing positions", &champ_id);
}
for pos in positions {
data_source.write_item_set(
&champion.data.get(&champ_id).unwrap(),
&pos,
&patch,
&path,
&client,
);
thread::sleep(Duration::from_millis(data_source.get_timeout()));
} else {
let path = lol_champs_dir.join(&champ_id).join("Recommended");
fs::create_dir_all(&path)?;
for pos in positions {
data_source.write_item_set(&champ, &pos, &patch, &path, &client);
thread::sleep(Duration::from_millis(data_source.get_timeout()));
}
}
} else {
error!("{} not found in LoL champs", &champ_id);
@ -127,13 +127,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
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() {
if key == champ.key {
return champ.id.to_owned();
return Some(champ.id.to_owned());
}
}
String::new()
None
}
#[cfg(target_os = "windows")]