From 95288e7c1e7b054094da20fdfc4faf3ed46d71fe Mon Sep 17 00:00:00 2001 From: tretrauit Date: Sun, 7 Jan 2024 20:10:31 +0700 Subject: [PATCH] fix(katana): parse wishlist from lookup So if there's no koibito then the Wishlisted section will move up... Also fixes parsing when wl > 1000 because it'll have a "," to make it easier for human to read. --- swordfish-common/src/utils/katana.rs | 30 +++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/swordfish-common/src/utils/katana.rs b/swordfish-common/src/utils/katana.rs index 8509c11..8d71866 100644 --- a/swordfish-common/src/utils/katana.rs +++ b/swordfish-common/src/utils/katana.rs @@ -211,15 +211,31 @@ pub fn parse_cards_from_katana_klu_lookup(content: &String) -> Option { None => return None, }; // Wishlist - let mut line_split = lines.nth(1).unwrap().split(" · "); - let wishlist = match line_split.nth(1) { - Some(series) => { - let mut series_string = series.to_string(); - series_string.remove_matches("**"); - match series_string.parse::() { + let mut line_split: Option> = None; + while line_split.is_none() { + line_split = match lines.next() { + Some(line) => { + if line.contains("Wishlisted") { + Some(line.split(" · ")) + } else { + None + } + } + None => { + error!("Failed to parse wishlist number: {}", content); + return None; + }, + } + } + let wishlist = match line_split?.nth(1) { + Some(wl) => { + let mut wl_string = wl.to_string(); + wl_string.remove_matches("**"); + wl_string.remove_matches(","); + match wl_string.parse::() { Ok(wishlist) => wishlist, Err(_) => { - error!("Failed to parse wishlist number: {}", series_string); + error!("Failed to parse wishlist number: {}", wl_string); return None; } }