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