1
0
Fork
You've already forked rss
1

Add thatskyshop support #2

Manually merged
lexisother merged 2 commits from lexisother/rss:thatskyshop into main 2025年10月07日 00:55:51 +02:00

View file

@ -8,3 +8,4 @@ pub mod moxie;
pubmod nue;
pubmod pwn_cat;
pubmod bsky;
pubmod thatskyshop;

75
src/feeds/thatskyshop.rs Normal file
View file

@ -0,0 +1,75 @@
useaxum::extract::Query;
userss::{ChannelBuilder,ItemBuilder};
useserde::Deserialize;
useserde_json::json;
usecrate::util::{net,res};
#[derive(Deserialize)]
pubstruct QueryData{
handle: String
}
pubasyncfn rss(query: Query<QueryData>)-> res::Res{
lethandle=&query.handle;
leturl="https://thatskyshop.com/api/2025-10/graphql.json";
letclient=reqwest::Client::new();
letproduct_data: Response={
letres=net::post_json(&client,url,&json!({
"operationName": "Product",
"query": format!("query Product($handle: String) {{ product(handle: $handle) {{ title onlineStoreUrl availableForSale }} }}"),
"variables": {
"handle": &handle
}
})).await?;
matchserde_json::from_str(&res){
Ok(val)=>val,
Err(_)=>returnres::err_static("Failed to parse response JSON")
}
};
dbg!(&product_data.data.product.available_for_sale);
letproduct=product_data.data.product;
letitem=ItemBuilder::default()
.title(format!(
"{} - {}",
product.title,
ifproduct.available_for_sale{
"ON SALE!!!"
}else{
"Sold out"
}
))
.link(product.url)
.build();
letfeed=ChannelBuilder::default()
.title(format!("thatskyshop - {} Tracker",product.title))
.link("https://thatskyshop.com")
.items(Vec::from([item]))
.build();
res::ok(feed.to_string())
}
#[derive(Deserialize)]
struct Response{
data: ProductContainer
}
#[derive(Deserialize)]
struct ProductContainer{
product: Product
}
#[derive(Deserialize)]
struct Product{
title: String,
#[serde(rename(deserialize = "onlineStoreUrl"))]
url: String,
#[serde(rename(deserialize = "availableForSale"))]
available_for_sale: bool,
}

View file

@ -17,6 +17,7 @@ async fn main() {
.route("/moxie.rss",get(feeds::moxie::rss))
.route("/nue.rss",get(feeds::nue::rss))
.route("/pwn_cat.rss",get(feeds::pwn_cat::rss))
.route("/thatskyshop.rss",get(feeds::thatskyshop::rss))
;
letport=matchenv::var("PORT"){

View file

@ -19,6 +19,26 @@ pub async fn fetch_txt(client: &reqwest::Client, url: &str) -> Result<String, Re
}
}
pubasyncfn post_json(client: &reqwest::Client,url: &str,json: &serde_json::Value)-> Result<String,Response>{
letres=client
.post(url)
.header(header::CONTENT_TYPE,"application/json")
.header(header::ACCEPT,"application/json")
.body(json.to_string())
.send()
.await;
letres=matchres{
Ok(res)=>res,
Err(_)=>returnres::err(format!("Failed to fetch {}",url))
};
matchres.text().await{
Ok(text)=>Ok(text),
Err(_)=>res::err(format!("Failed to parse text response from {}",url))
}
}
/// Fetches the contents of a URL and parses the HTML.
pubasyncfn fetch(client: &reqwest::Client,url: &str)-> Result<Html,Response>{
fetch_txt(client,url).await

Reference in a new issue
basil/rss