feat: properly print json response to stdout
This commit is contained in:
+1
-2
@@ -6,12 +6,11 @@ mod rutracker;
|
|||||||
slint::include_modules!();
|
slint::include_modules!();
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
rutracker::search("test");
|
|
||||||
let ui = AppWindow::new()?;
|
let ui = AppWindow::new()?;
|
||||||
|
|
||||||
ui.on_request_text_input(|text| {
|
ui.on_request_text_input(|text| {
|
||||||
let text = text.trim();
|
|
||||||
println!("User input: {}", text);
|
println!("User input: {}", text);
|
||||||
|
let response = rutracker::search(&text);
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.run()?;
|
ui.run()?;
|
||||||
|
|||||||
+9
-3
@@ -1,6 +1,12 @@
|
|||||||
|
use serde_json::Value;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
pub async fn search(value: &str) {
|
pub async fn search(value: &str) -> Result<Value, reqwest::Error> {
|
||||||
let api_url = "https://api.michijackson.xyz/search?q=".to_owned();
|
let api_url = "https://api.michijackson.xyz/search?q=".to_owned();
|
||||||
let results = reqwest::get(api_url + value).await;
|
let results = reqwest::get(api_url + value).await?;
|
||||||
println!("{:?}", results);
|
let text = results.text().await?;
|
||||||
|
let v: Value = serde_json::from_str(&text).expect("Failed to parse JSON");
|
||||||
|
let data = &v["data"];
|
||||||
|
println!("{:?}", data);
|
||||||
|
Ok(v)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user