Skip to navigation
Parsing rakuten book xml api with rust
18.10.22
use actix_web::{web, Responder, HttpRequest}; use reqwest; use async_std::fs; use std::time::{SystemTime, UNIX_EPOCH}; use std::env; use serde::{Serialize, Deserialize}; use awc::Client; use url::Url; use dirs; use serde_roxmltree::from_str; /* test: http://127.0.0.1:8088/book docs: https://developers.rakutenadvertising.com/documentation/en-US/affiliate_apis#/Product%20Search/get_productsearch_1_0 https://actix.rs/actix-web/awc/index.html pub async fn rakuten_productsearch(token:&str, keyword: &str)-> Result<(), Box
> { let mut _data = "".to_string(); let client = Client::new(); let url = Url::parse_with_params("https://api.linksynergy.com/productsearch/1.0", &[("mid", "666666"), ("max", "2"),("keyword", keyword)])?; let res = client .get(url.as_str()) .insert_header(("User-Agent", "Actix-web")) .insert_header(("Authorization", format!("Bearer {0}",token))) .send() .await; let _bin = res.unwrap().body().await.unwrap(); let _s = String::from_utf8_lossy(&_bin); let r = from_str::
(&_s)?; println!("{:?}",r.TotalMatches); println!("{:?}",r.TotalPages); for i in r.item { println!("{:?}",i.sku); println!("{:?}",i.category.primary); println!("{:?}",i.category.secondary); println!("{:?}",i.price.text); println!("{:?}",i.price.currency); println!("{:?}",i.description.short); println!("{:?}",i.description.long); println!("{:?}",i.keywords); println!("{:?}",i.linkurl); println!("{:?}",i.imageurl); } return Ok(()) } #[derive(Deserialize,Debug)] struct Resultx { TotalMatches: String, TotalPages: String, item: Vec
} #[derive(Deserialize,Debug)] struct Item<> { mid: String, merchantname: String, linkid: String, createdon: String, sku: String, productname: String, category: Category, price: Price, description: Description, keywords: String, linkurl: String, imageurl: String, } #[derive(Deserialize,Debug)] struct Description { short: String, long: String, } #[derive(Deserialize,Debug)] struct Category { primary: String, secondary: String, } #[derive(Deserialize,Debug)] struct Price { #[serde(rename = "$text")] text: String, currency: String, }
https://lib.rs/crates/serde-roxmltree
Reply
Anonymous
Information Epoch 1742413603
Write simple parts connected by clean interfaces.
Home
Notebook
Contact us