Don't look at that awful test...
I have tested it on the Oracle cards - so should like... mostly work for cards Except for, I think, mistakes? in the Scryfall database.
This commit is contained in:
@@ -61,11 +61,11 @@ struct ScryfallCard {
|
|||||||
// https://scryfall.com/docs/api/cards#print-fields
|
// https://scryfall.com/docs/api/cards#print-fields
|
||||||
pub artist: Option<String>,
|
pub artist: Option<String>,
|
||||||
pub artist_ids: Option<Vec<String>>,
|
pub artist_ids: Option<Vec<String>>,
|
||||||
pub attraction_lights: Option<Vec<String>>, // TODO: I'm not actually sure what these look like - I should test
|
pub attraction_lights: Option<Vec<u8>>,
|
||||||
pub booster: bool,
|
pub booster: bool,
|
||||||
#[serde(rename = "border_color")]
|
#[serde(rename = "border_color")]
|
||||||
pub border_colour: BorderColour,
|
pub border_colour: BorderColour,
|
||||||
pub card_back_id: Uuid,
|
pub card_back_id: Option<Uuid>, // Scryfall docs says this should not be null, but ZHS Growing Rites of Itlimoc seems to not have one... maybe it's the back side?
|
||||||
pub collector_number: String,
|
pub collector_number: String,
|
||||||
pub content_warning: Option<bool>,
|
pub content_warning: Option<bool>,
|
||||||
pub digital: bool,
|
pub digital: bool,
|
||||||
@@ -173,6 +173,10 @@ enum Colour {
|
|||||||
Red,
|
Red,
|
||||||
#[serde(rename = "G")]
|
#[serde(rename = "G")]
|
||||||
Green,
|
Green,
|
||||||
|
#[serde(rename = "C")] // I don't think it's meant to work like this... but eh
|
||||||
|
Colourless,
|
||||||
|
#[serde(rename = "T")] // See "Sole Performer"
|
||||||
|
Tap
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
@@ -310,7 +314,9 @@ enum FrameEffect {
|
|||||||
#[serde(rename = "upsidedowndfc")]
|
#[serde(rename = "upsidedowndfc")]
|
||||||
UpsideDownDFC,
|
UpsideDownDFC,
|
||||||
#[serde(rename = "spree")]
|
#[serde(rename = "spree")]
|
||||||
Spree
|
Spree,
|
||||||
|
#[serde(rename = "fullart")]
|
||||||
|
FullArt
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
@@ -321,7 +327,11 @@ enum Game {
|
|||||||
#[serde(rename = "mtgo")]
|
#[serde(rename = "mtgo")]
|
||||||
MTGO,
|
MTGO,
|
||||||
#[serde(rename = "arena")]
|
#[serde(rename = "arena")]
|
||||||
Arena
|
Arena,
|
||||||
|
#[serde(rename = "astral")]
|
||||||
|
Astral,
|
||||||
|
#[serde(rename = "sega")]
|
||||||
|
Sega
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
@@ -449,17 +459,9 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn try_deserialise_all_cards() {
|
#[ignore]
|
||||||
// TODO Actually write this funtion.
|
fn try_deserialise_all_cards_line_by_line() {
|
||||||
// The idea will be to run over one of the Scryfall dumps of all the cards so I can be
|
// This function is uuuuuuugly and I'm sure a terrible way to go about things
|
||||||
// confident I've got things working.
|
|
||||||
// I noticed that Scryfall very helpfully provides their dumps with 1 card per line.
|
|
||||||
// So using something like the link below should hopefully mean I don't have to load in the
|
|
||||||
// whole 2+GB file all at once
|
|
||||||
// https://doc.rust-lang.org/std/io/trait.BufRead.html#method.lines
|
|
||||||
// I think that's what it should do at least. I bet it'll still take a while tho.
|
|
||||||
// If that doesn't work - I should try somehow use the serde from_reader function
|
|
||||||
// I don't 100% know how I'll use that though.
|
|
||||||
let mut f = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
let mut f = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||||
f.push("test_files/all-cards.json");
|
f.push("test_files/all-cards.json");
|
||||||
assert!(f.exists(), "You need to download the all-cards-... file from Scryfall bulk data. Can be found here: https://scryfall.com/docs/api/bulk-data and rename to all-cards.json");
|
assert!(f.exists(), "You need to download the all-cards-... file from Scryfall bulk data. Can be found here: https://scryfall.com/docs/api/bulk-data and rename to all-cards.json");
|
||||||
@@ -467,7 +469,13 @@ mod tests {
|
|||||||
let reader = BufReader::new(ac);
|
let reader = BufReader::new(ac);
|
||||||
for line in reader.lines().skip(1) {
|
for line in reader.lines().skip(1) {
|
||||||
let mut line = line.unwrap();
|
let mut line = line.unwrap();
|
||||||
line.pop();
|
let c = line.pop().unwrap();
|
||||||
|
// this is so dumb...
|
||||||
|
if c == '}' {
|
||||||
|
line.push('}');
|
||||||
|
}
|
||||||
|
|
||||||
|
if line.len() < 1 { continue };
|
||||||
let a_card: Result<ScryfallCard, serde_json::Error> = serde_json::from_str(&line.as_ref());
|
let a_card: Result<ScryfallCard, serde_json::Error> = serde_json::from_str(&line.as_ref());
|
||||||
match a_card {
|
match a_card {
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
@@ -479,6 +487,5 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// FIXME: Skip the last line
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user