diff --git a/scryfall_deser/README.md b/scryfall_deser/README.md index d051bdc..2cc5297 100644 --- a/scryfall_deser/README.md +++ b/scryfall_deser/README.md @@ -90,7 +90,11 @@ Fingers crossed that all compiled and stuff... then copy the bin cp build/rofi ~/bin ``` -## TODO & Features That Could be Good +## FIXME, TODO & Features That Could be Good + * Remove the non-card cards. Examples I've come across are: + ** Planes: Black Lotus Lounge + ** Art Cards: https://scryfall.com/card/altr/15/%C3%A9owyn-fearless-knight-%C3%A9owyn-fearless-knight?utm_source=api + * Allow exiting the script early (i.e. I hit CTRL+g just exits everything) * Misspelled cards, if only 1 hit that makes sense, could just work * Display the actual card image (probably won't do this) * Some kind of auto-magic direct link between the return codes set out in `main.r`s and the `rofi` scripts. Currently I need to manually make sure they're the same between the `rust` code and the `sh` code. diff --git a/scryfall_deser/scripts/search_with_rofi_with_args.sh b/scryfall_deser/scripts/search_with_rofi_with_args.sh index a9aca80..23ea374 100755 --- a/scryfall_deser/scripts/search_with_rofi_with_args.sh +++ b/scryfall_deser/scripts/search_with_rofi_with_args.sh @@ -7,6 +7,16 @@ CARDS=$(/home/arthurr/code/mini_projects/scryfall_deser/target/debug/scryfall_de RETURN=$? echo $RETURN +####################### +## Exact card found - just print the card +####################### +if [ $RETURN -eq 200 ]; then + +rofi -e "$CARDS" + +fi + + ####################### ## Cards to select from ####################### diff --git a/scryfall_deser/src/db.rs b/scryfall_deser/src/db.rs index 5dfdbf6..20a633a 100644 --- a/scryfall_deser/src/db.rs +++ b/scryfall_deser/src/db.rs @@ -105,6 +105,8 @@ pub fn get_card_by_name(name: &str, name_type: GetNameType) -> Option { FROM cards WHERE lowercase_name = (?1)" } }; + dbg!(name); + dbg!(&sql); let mut stmt = conn.prepare(sql).unwrap(); let mut rows = stmt.query([name]).unwrap(); match rows.next().unwrap() { diff --git a/scryfall_deser/src/main.rs b/scryfall_deser/src/main.rs index 02009e8..028a018 100644 --- a/scryfall_deser/src/main.rs +++ b/scryfall_deser/src/main.rs @@ -17,12 +17,16 @@ impl Termination for MtgCardExit { MtgCardExit::EmptySearchString => ExitCode::from(101), MtgCardExit::NoExactMatchCard => ExitCode::from(102), MtgCardExit::DidYouMean => ExitCode::from(105), + MtgCardExit::ExactCardFound => ExitCode::from(200), + MtgCardExit::UpdateSuccess => ExitCode::from(201), } } } enum MtgCardExit { Success, + UpdateSuccess, + ExactCardFound, EmptySearchString, NoExactMatchCard, DidYouMean, @@ -51,7 +55,7 @@ fn exact_search(search_strings: Vec) -> MtgCardExit { } Some(c) => { println!("{}", c); - MtgCardExit::Success + MtgCardExit::ExactCardFound } } } @@ -76,7 +80,7 @@ fn main() -> MtgCardExit { path.push(update); // FIXME - if you pass a bad file or something, it just deletes the db update_db_with_file(path); - return MtgCardExit::Success; + return MtgCardExit::UpdateSuccess; } if args.search_text.is_empty() { dbg!("You need to put some card text to search"); @@ -109,9 +113,11 @@ fn main() -> MtgCardExit { } return MtgCardExit::DidYouMean; } else if matching_cards.len() == 1 { - let card = get_card_by_name(&matching_cards[0].name, GetNameType::LowercaseName).unwrap(); + // FIXME - theres a bug in here - try searching Nalf + let card = get_card_by_name(&matching_cards[0].name, GetNameType::Name).unwrap(); println!("{}", card); - return MtgCardExit::Success; + // TODO update this to be more meaningful + return MtgCardExit::ExactCardFound; } else { for card in matching_cards { println!( @@ -121,6 +127,7 @@ fn main() -> MtgCardExit { .name ); } + // TODO update this to be more meaningful return MtgCardExit::Success; } }