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 title = client.get_title("1218842").await?;
println!("Title: {}", title);
Ok(())
}
Get the text result
use std::error::Error;
use shindan_maker::{ShindanClient, ShindanDomain, ShindanTextResult};
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let client = ShindanClient::new(ShindanDomain::En)?;
let result = client.get_text_result("1218842", "test_user").await?;
let ShindanTextResult { title, content } = result;
println!("Result title: {}", title);
println!("Result content: {:#?}", content);
Ok(())
}
Printing text segments
use shindan_maker::{ShindanClient, ShindanDomain, ShindanTextResult};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = ShindanClient::new(ShindanDomain::En)?;
let result = client.get_text_result("1218842", "test_user").await?;
let ShindanTextResult { title, content } = result;
println!("Result title: {}", title);
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);
Ok(())
}
Filtering segments by type
use shindan_maker::{ShindanClient, ShindanDomain, filter_segments_by_type};
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = ShindanClient::new(ShindanDomain::En)?;
let result = client.get_text_result("1218842", "test_user").await?;
println!("Result title: {}", result.title);
let text_segments = filter_segments_by_type(&result.content, "text");
assert_eq!(text_segments.len(), 2);
Ok(())
}
Get the image result
use std::error::Error;
use base64::Engine;
use shindan_maker::{ShindanClient, ShindanDomain};
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let client = ShindanClient::new(ShindanDomain::En)?.init_browser()?;
let result = client.get_image_result("1218842", "test_user").await?;
println!("Result title: {}", result.title);
let png_data = base64::prelude::BASE64_STANDARD.decode(result.base64)?;
std::fs::write("test.png", png_data)?;
Ok(())
}
License