feat(katana): c o:w parser
This commit is contained in:
@ -26,7 +26,6 @@ pub fn init() {
|
||||
}
|
||||
|
||||
pub async fn query_card(name: &str, series: &str) -> Option<Card> {
|
||||
// todo!("Query card from database");
|
||||
KATANA
|
||||
.get()
|
||||
.unwrap()
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
use crate::structs::Card;
|
||||
use log::{error, trace};
|
||||
|
||||
// atopwl
|
||||
pub fn parse_cards_from_qingque_atopwl(content: &String) -> Vec<Card> {
|
||||
let mut cards: Vec<Card> = Vec::new();
|
||||
for line in content.split("\n") {
|
||||
@ -59,3 +60,58 @@ pub fn parse_cards_from_qingque_atopwl(content: &String) -> Vec<Card> {
|
||||
}
|
||||
cards
|
||||
}
|
||||
|
||||
// kc o:w
|
||||
pub fn parse_cards_from_katana_kc_ow(content: &String) -> Vec<Card> {
|
||||
let mut cards: Vec<Card> = Vec::new();
|
||||
for line in content.split("\n") {
|
||||
trace!("Parsing line: {}", line);
|
||||
if !line.ends_with("**") {
|
||||
continue;
|
||||
}
|
||||
let mut line_split = line.split(" · ");
|
||||
let tag_wl_block = line_split.nth(0).unwrap();
|
||||
let mut wl_block = match tag_wl_block.split("`").nth(1) {
|
||||
Some(wl_block) => {
|
||||
// If one does not start with ♡, it is not a wishlist command
|
||||
// then we'll just break entirely.
|
||||
if !wl_block.starts_with("♡") {
|
||||
break;
|
||||
}
|
||||
wl_block.to_string()
|
||||
},
|
||||
None => break,
|
||||
};
|
||||
wl_block.remove(0);
|
||||
wl_block = wl_block.trim().to_string();
|
||||
let wishlist = match wl_block.parse::<u32>() {
|
||||
Ok(wishlist) => wishlist,
|
||||
Err(_) => {
|
||||
error!("Failed to parse wishlist number: {}", wl_block);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let series = match line_split.nth(4) {
|
||||
Some(series) => series.to_string(),
|
||||
None => continue,
|
||||
};
|
||||
let name = match line_split.next() {
|
||||
Some(name) => {
|
||||
let mut name_string = name.to_string();
|
||||
name_string.remove_matches("**");
|
||||
name_string
|
||||
}
|
||||
None => continue,
|
||||
};
|
||||
let card = Card {
|
||||
wishlist: Some(wishlist),
|
||||
name,
|
||||
series,
|
||||
print: 0,
|
||||
last_update_ts: 0,
|
||||
};
|
||||
trace!("Parsed card: {:?}", card);
|
||||
cards.push(card);
|
||||
}
|
||||
cards
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user