ShindanMaker
A Rust library for interacting with ShindanMaker, the popular personality quiz service.
Features
- Asynchronous API
- Multi-domain support (JP, EN, CN, KR, TH)
- Easy shindan submission and result parsing
- Image result support (optional, headless browser required)
Usage
[dependencies]
tokio = { version = "1", features = ["full"] }
shindan-maker = { version = "0.1", features = ["full"] }
Example
Get the shindan title
use std::error::Error;
use shindan_maker::{ShindanClient, ShindanDomain};
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let client = ShindanClient::new(ShindanDomain::En)?;
let shindan_id = "1221154";
let title = client.get_title(shindan_id).await?;
println!("Shindan title: {}", title);
}
Get the text result
use std::error::Error;
use shindan_maker::{ShindanClient, ShindanDomain, ShindanResult, Segment, ShindanTextResult};
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let client = ShindanClient::new(ShindanDomain::En)?;
let shindan_id = "1221154";
let text_result = client.get_text_result(shindan_id, "test_name").await?;
let ShindanTextResult { title, content } = text_result;
println!("Result title: {}", title);
println!("Result content: {:#?}", content);
Ok(())
}
Parse the text result
use shindan_maker::{ShindanClient, ShindanDomain, ShindanResult, Segment, ShindanTextResult};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut text = String::new();
for segment in content.iter() {
match segment.type_.as_str() {
"text" => {
text.push_str(&segment.get_text().unwrap());
}
"image" => {
text.push_str(&segment.get_image_url().unwrap());
}
_ => {}
}
}
println!("Result text: {}", text);
for segment in content.iter().filter_map(|s| s.get_text()) {
println!("Text: {}", segment);
}
for segment in content.iter().filter_map(|s| s.get_image_url()) {
println!("Image URL: {}", segment);
}
let text_segments: Vec<&Segment> = shindan_maker::filter_segments_by_type(&content, "text");
println!("Number of text segments: {}", text_segments.len());
Ok(())
}
Get the image result
use base64::Engine;
use std::error::Error;
use shindan_maker::{ShindanClient, ShindanDomain, ShindanImageResult};
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let client = ShindanClient::new(ShindanDomain::En)?.init_browser()?;
let shindan_id = "1221154";
let image_result = client.get_image_result(shindan_id, "test_name").await?;
let ShindanImageResult { title, base64 } = image_result;
let png_data = base64::prelude::BASE64_STANDARD.decode(base64)?;
std::fs::write("test.png", png_data)?;
Ok(())
}
License