-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
523 additions
and
39 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod product; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"@type": "Product", | ||
"@id": "https://tweakers.net/pricewatch/1855004/anker-737-power-bank-powercore-24k.html#Product-1855004", | ||
"name": "Anker 737 Power Bank (PowerCore 24K)", | ||
"@context": "https://schema.org", | ||
"url": "https://tweakers.net/pricewatch/1855004/anker-737-power-bank-powercore-24k.html", | ||
"brand": { | ||
"@type": "Brand", | ||
"name": "Anker", | ||
"url": "https://tweakers.net/merk/2742/anker/" | ||
}, | ||
"image": [ | ||
"https://tweakers.net/ext/i/2005317900.webp", | ||
"https://tweakers.net/ext/i/2005565422.jpeg", | ||
"https://tweakers.net/ext/i/2006644124.jpeg", | ||
"https://tweakers.net/ext/i/2006644126.jpeg", | ||
"https://tweakers.net/ext/i/2006644128.jpeg", | ||
"https://tweakers.net/ext/i/2006644130.jpeg", | ||
"https://tweakers.net/ext/i/2006644132.jpeg", | ||
"https://tweakers.net/ext/i/2006644134.jpeg", | ||
"https://tweakers.net/ext/i/2006644136.jpeg" | ||
], | ||
"gtin13": [ | ||
"0194644098728" | ||
], | ||
"mpn": [ | ||
"a1289", | ||
"A1289011" | ||
], | ||
"description": "1x USB A, 2x USB type-C", | ||
"aggregateRating": { | ||
"@type": "AggregateRating", | ||
"ratingValue": 3.5, | ||
"ratingCount": 4 | ||
}, | ||
"offers": { | ||
"@type": "AggregateOffer", | ||
"lowPrice": 84, | ||
"highPrice": 153, | ||
"offerCount": 15, | ||
"priceCurrency": "EUR" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod tweakers; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use scraper::{Html, Selector}; | ||
use serde::{Deserialize, Serialize}; | ||
use thiserror::Error; | ||
|
||
// "{\"@type\":\"Product\",\"@id\":\"https:\\/\\/tweakers.net\\/pricewatch\\/1855004\\/anker-737-power-bank-powercore-24k.html#Product-1855004\",\"name\":\"Anker 737 Power Bank (PowerCore 24K)\",\"@context\":\"https:\\/\\/schema.org\",\"url\":\"https:\\/\\/tweakers.net\\/pricewatch\\/1855004\\/anker-737-power-bank-powercore-24k.html\",\"brand\":{\"@type\":\"Brand\",\"name\":\"Anker\",\"url\":\"https:\\/\\/tweakers.net\\/merk\\/2742\\/anker\\/\"},\"image\":[\"https:\\/\\/tweakers.net\\/ext\\/i\\/2005317900.webp\",\"https:\\/\\/tweakers.net\\/ext\\/i\\/2005565422.jpeg\",\"https:\\/\\/tweakers.net\\/ext\\/i\\/2006644124.jpeg\",\"https:\\/\\/tweakers.net\\/ext\\/i\\/2006644126.jpeg\",\"https:\\/\\/tweakers.net\\/ext\\/i\\/2006644128.jpeg\",\"https:\\/\\/tweakers.net\\/ext\\/i\\/2006644130.jpeg\",\"https:\\/\\/tweakers.net\\/ext\\/i\\/2006644132.jpeg\",\"https:\\/\\/tweakers.net\\/ext\\/i\\/2006644134.jpeg\",\"https:\\/\\/tweakers.net\\/ext\\/i\\/2006644136.jpeg\"],\"gtin13\":[\"0194644098728\"],\"mpn\":[\"a1289\",\"A1289011\"],\"description\":\"1x USB A, 2x USB type-C\",\"aggregateRating\":{\"@type\":\"AggregateRating\",\"ratingValue\":3.5,\"ratingCount\":4},\"offers\":{\"@type\":\"AggregateOffer\",\"lowPrice\":84,\"highPrice\":153,\"offerCount\":15,\"priceCurrency\":\"EUR\"}}" | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct TweakerProduct { | ||
pub id: String, | ||
} | ||
|
||
#[derive(Debug, Error)] | ||
pub enum TweakerError { | ||
#[error(transparent)] | ||
Request(#[from] reqwest::Error), | ||
} | ||
|
||
// Fetch https://tweakers.net/pricewatch/1855004/anker-737-power-bank-powercore-24k/specificaties/ | ||
// and parse the application/ld+json | ||
pub async fn get_by_tweaker_id(tweaker_id: String) -> Result<TweakerProduct, TweakerError> { | ||
|
||
let response = reqwest::get(format!("https://tweakers.net/pricewatch/{}/specificaties/", tweaker_id)).await.unwrap(); | ||
let body = response.text().await.unwrap(); | ||
|
||
// println!("{}", body); | ||
// // regex match for <script type="application/ld+json"> ... </script> | ||
// let re = regex::Regex::new(r#"<script type="application/ld\+json">\s*?(.*?)\s*?</script>"#).unwrap(); | ||
// let captures = re.captures(&body).unwrap(); | ||
|
||
// for capture in captures.iter() { | ||
// println!("{}", capture.unwrap().as_str()); | ||
// } | ||
|
||
let document = Html::parse_document(&body); | ||
|
||
// Define a selector for <script> tags with type="application/ld+json" | ||
let selector = Selector::parse(r#"script[type="application/ld+json"]"#).unwrap(); | ||
|
||
// Extract the content of matching <script> tags | ||
let ld_json_scripts: Vec<String> = document | ||
.select(&selector) | ||
.filter_map(|element| element.text().next().map(|text| text.to_string())) | ||
.collect(); | ||
|
||
println!("{:?}", ld_json_scripts); | ||
|
||
Ok(TweakerProduct { | ||
id: "123".to_string(), | ||
}) | ||
} | ||
|
||
#[async_std::test] | ||
async fn test_get_by_tweaker_id() { | ||
let product = get_by_tweaker_id("1855004".to_string()).await.unwrap(); | ||
println!("{:?}", product); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ mod auth; | |
mod state; | ||
mod models; | ||
mod routes; | ||
mod ingress; | ||
mod database; | ||
|
||
#[async_std::main] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { createFileRoute } from '@tanstack/react-router'; | ||
|
||
export const Route = createFileRoute('/$itemId')({ | ||
component: () => <div>Hello /$itemId!</div>, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { createFileRoute } from '@tanstack/react-router'; | ||
|
||
export const Route = createFileRoute('/item/$itemId/edit')({ | ||
component: () => <div>Hello /item/$itemId/edit!</div>, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { createFileRoute } from '@tanstack/react-router'; | ||
|
||
export const Route = createFileRoute('/item/$itemId/')({ | ||
component: () => <div>Hello /item/$itemId!</div>, | ||
}); |