Add stock info to scraper

This commit is contained in:
SkyfallWasTaken 2024-07-01 18:00:37 +01:00
parent 4995a1e172
commit 4aad2a3228
2 changed files with 8 additions and 1 deletions

View file

@ -15,6 +15,9 @@ pub struct ShopItem {
#[serde(rename = "Cost Hours")]
pub price: i32,
#[serde(rename = "Stock")]
pub stock: Option<i32>,
}
pub type ShopItems = Vec<ShopItem>;

View file

@ -25,10 +25,14 @@ async fn run_scrape(env: Env) -> Result<String> {
let mut result = Vec::new();
for item in available_items {
result.push(format!(
"`{full_name}` - {price} {}",
"`{full_name}` - {price} {} - Stock: {stock}",
if item.price == 1 { "ticket" } else { "tickets" },
full_name = item.full_name.trim(),
price = item.price,
stock = item
.stock
.map(|stock| stock.to_string())
.unwrap_or("Unlimited".into())
));
}