bump version to 0.1.1
- fix missing side dishes because of missing image
This commit is contained in:
parent
a3cc82fc55
commit
11bd6b4bca
|
@ -1223,7 +1223,7 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
|||
|
||||
[[package]]
|
||||
name = "mensa-upb-api"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
dependencies = [
|
||||
"actix-cors",
|
||||
"actix-governor",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "mensa-upb-api"
|
||||
description = "A web scraper api for the canteens of the University of Paderborn"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
|
|
@ -2,32 +2,40 @@
|
|||
<div id="main_dishes"></div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
fetch("http://localhost:8080/menu/forum")
|
||||
fetch(
|
||||
"http://localhost:8080/menu/forum" +
|
||||
(new Date().getHours() >= 15 ? "?d=1" : "")
|
||||
)
|
||||
.then((d) => d.json())
|
||||
.then((menu) => {
|
||||
const main_dishes_container = /** @type {HTMLDivElement} */ (document.querySelector(
|
||||
"#mensa #main_dishes"
|
||||
));
|
||||
const main_dishes_container = /** @type {HTMLDivElement} */ (
|
||||
document.querySelector("#mensa #main_dishes")
|
||||
);
|
||||
main_dishes_container.style.display = "grid";
|
||||
main_dishes_container.style.gridTemplateColumns = "repeat(auto-fit, minmax(150px, 1fr))";
|
||||
main_dishes_container.style.gridTemplateColumns =
|
||||
"repeat(auto-fit, minmax(150px, 1fr))";
|
||||
main_dishes_container.style.gridGap = "10px";
|
||||
if (
|
||||
main_dishes_container != null &&
|
||||
menu != null &&
|
||||
menu.main_dishes != null
|
||||
) {
|
||||
for (let dish of menu.main_dishes) {
|
||||
if (main_dishes_container != null && menu != null) {
|
||||
const main_dishes = menu.main_dishes ?? [];
|
||||
const side_dishes = menu.side_dishes ?? [];
|
||||
const desserts = menu.desserts ?? [];
|
||||
for (let dish of [
|
||||
...main_dishes,
|
||||
...side_dishes,
|
||||
...desserts,
|
||||
]) {
|
||||
let dish_el = document.createElement("div");
|
||||
dish_el.classList.add("dish");
|
||||
dish_el.style.display = "flex";
|
||||
dish_el.style.flexDirection = "column";
|
||||
dish_el.style.alignItems = "center";
|
||||
let img_el = document.createElement("img");
|
||||
img_el.src = dish.image_src;
|
||||
img_el.style.maxWidth = "80%";
|
||||
img_el.style.objectFit = "cover";
|
||||
|
||||
dish_el.appendChild(img_el);
|
||||
if (dish.image_src != null) {
|
||||
let img_el = document.createElement("img");
|
||||
img_el.src = dish.image_src;
|
||||
img_el.style.maxWidth = "80%";
|
||||
img_el.style.objectFit = "cover";
|
||||
dish_el.appendChild(img_el);
|
||||
}
|
||||
let name_el = document.createElement("p");
|
||||
name_el.classList.add("dish-name");
|
||||
name_el.innerText = dish.name;
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
use std::str::FromStr;
|
||||
|
||||
use const_format::concatcp;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum::EnumIter;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, EnumIter, Hash)]
|
||||
#[derive(
|
||||
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, EnumIter, Hash, Serialize, Deserialize,
|
||||
)]
|
||||
pub enum Canteen {
|
||||
Forum,
|
||||
Academica,
|
||||
|
|
10
src/dish.rs
10
src/dish.rs
|
@ -7,12 +7,11 @@ use crate::Canteen;
|
|||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Dish {
|
||||
name: String,
|
||||
image_src: String,
|
||||
image_src: Option<String>,
|
||||
price_students: Option<String>,
|
||||
price_employees: Option<String>,
|
||||
price_guests: Option<String>,
|
||||
extras: Vec<String>,
|
||||
#[serde(skip)]
|
||||
canteens: Vec<Canteen>,
|
||||
}
|
||||
|
||||
|
@ -65,8 +64,11 @@ impl Dish {
|
|||
.to_string();
|
||||
|
||||
let img_selector = scraper::Selector::parse(".img img").ok()?;
|
||||
let img_src_path = element.select(&img_selector).next()?.value().attr("src")?;
|
||||
let img_src = format!("https://www.studierendenwerk-pb.de/{}", img_src_path);
|
||||
let img_src = element.select(&img_selector).next().and_then(|el| {
|
||||
el.value()
|
||||
.attr("src")
|
||||
.map(|img_src_path| format!("https://www.studierendenwerk-pb.de/{}", img_src_path))
|
||||
});
|
||||
|
||||
let html_price_selector = scraper::Selector::parse(".desc .price").ok()?;
|
||||
let mut prices = element
|
||||
|
|
Loading…
Reference in New Issue