|
|
|
@@ -25,6 +25,7 @@ from werkzeug.routing import BuildError
|
|
|
|
|
from jinja2 import TemplateNotFound
|
|
|
|
|
import os
|
|
|
|
|
import sys
|
|
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
|
|
|
|
|
|
# Ensure imports work regardless of whether gunicorn starts in /app or /app/Web.
|
|
|
|
|
_CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
@@ -4123,10 +4124,13 @@ def student_card_barcode_download():
|
|
|
|
|
c.setLineWidth(2)
|
|
|
|
|
c.line(x_pos, y_pos - 10*mm, x_pos + card_width, y_pos - 10*mm)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
school_name = cfg.get_school_info()
|
|
|
|
|
school_name = school_name["name"]
|
|
|
|
|
# "SCHÜLERAUSWEIS" text in header
|
|
|
|
|
c.setFont("Helvetica-Bold", 9)
|
|
|
|
|
c.setFillColor(white)
|
|
|
|
|
c.drawString(x_pos + 3*mm, y_pos - 6.5*mm, "SCHÜLERAUSWEIS")
|
|
|
|
|
c.drawString(x_pos + 3*mm, y_pos - 6.5*mm, f"SCHÜLERAUSWEIS - {str(school_name)}")
|
|
|
|
|
|
|
|
|
|
# Student name - large and bold
|
|
|
|
|
c.setFillColor(text_dark)
|
|
|
|
@@ -4150,7 +4154,7 @@ def student_card_barcode_download():
|
|
|
|
|
c.setFillColor(text_dark)
|
|
|
|
|
c.setFont("Helvetica-Bold", 9)
|
|
|
|
|
c.drawString(x_pos + 3*mm, y_pos - 28*mm, card['Klasse'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Right barcode section with border highlight
|
|
|
|
|
barcode_x_start = x_pos + info_width + 1*mm
|
|
|
|
|
c.setFillColor(accent_color)
|
|
|
|
@@ -9539,6 +9543,134 @@ def _fetch_from_open_library(clean_isbn):
|
|
|
|
|
print(f"OpenLibrary Search error: {e}")
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
def _fetch_from_isbn_de(clean_isbn):
|
|
|
|
|
"""
|
|
|
|
|
Source 4: isbn.de (Maßgeschneidertes Scraping basierend auf realem HTML)
|
|
|
|
|
Extrahiert alle Buchdaten inklusive Preise aus den Meta-Tags und der Sidebar.
|
|
|
|
|
"""
|
|
|
|
|
try:
|
|
|
|
|
url = f"https://www.isbn.de/buch/{clean_isbn}"
|
|
|
|
|
headers = {
|
|
|
|
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response = requests.get(url, headers=headers, timeout=5)
|
|
|
|
|
if response.status_code != 200:
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
soup = BeautifulSoup(response.text, 'html.parser')
|
|
|
|
|
|
|
|
|
|
# 1. Titel aus Meta-Tags extrahieren (extrem zuverlässig)
|
|
|
|
|
title_meta = soup.find('meta', property='og:title')
|
|
|
|
|
title = title_meta.get('content', '').strip() if title_meta else None
|
|
|
|
|
if not title:
|
|
|
|
|
h1_elem = soup.find('h1')
|
|
|
|
|
title = h1_elem.text.strip() if h1_elem else "Unknown Title"
|
|
|
|
|
|
|
|
|
|
# Falls Fehler- oder Suchseite
|
|
|
|
|
if "nicht gefunden" in title.lower() or "suche" in title.lower():
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
# --- Hilfsfunktion zum Parsen der .infotab-Sidebar-Struktur ---
|
|
|
|
|
def get_sidebar_value(keyword):
|
|
|
|
|
infotab = soup.find(class_='infotab')
|
|
|
|
|
if infotab:
|
|
|
|
|
for d in infotab.find_all('div'):
|
|
|
|
|
if d.text.strip().lower() == keyword.lower():
|
|
|
|
|
parent = d.parent
|
|
|
|
|
# Label vom Gesamttext abziehen, um nur den Wert zu erhalten
|
|
|
|
|
return parent.text.replace(d.text, '', 1).strip()
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
# 2. Verlag holen
|
|
|
|
|
publisher = get_sidebar_value('verlag')
|
|
|
|
|
if not publisher:
|
|
|
|
|
publisher = "Unknown Publisher"
|
|
|
|
|
|
|
|
|
|
# 3. Erscheinungsdatum (Aus Meta-Tag oder Sidebar)
|
|
|
|
|
date_meta = soup.find('meta', property='og:book:release_date')
|
|
|
|
|
if date_meta and date_meta.get('content'):
|
|
|
|
|
published_date = date_meta.get('content', '').strip()
|
|
|
|
|
else:
|
|
|
|
|
published_date = get_sidebar_value('erschienen am')
|
|
|
|
|
|
|
|
|
|
if not published_date:
|
|
|
|
|
published_date = "Unknown Date"
|
|
|
|
|
|
|
|
|
|
# 4. Autor (Da Schulbuch-Workbooks oft keinen Einzelautor haben, kluger Fallback)
|
|
|
|
|
author_meta = soup.find('meta', property='og:book:author')
|
|
|
|
|
author = author_meta.get('content', '').strip() if author_meta else ""
|
|
|
|
|
if not author:
|
|
|
|
|
author = get_sidebar_value('autor') or get_sidebar_value('herausgeber')
|
|
|
|
|
|
|
|
|
|
if not author:
|
|
|
|
|
author = f"{publisher} Redaktion" if publisher != "Unknown Publisher" else "Unknown Author"
|
|
|
|
|
|
|
|
|
|
# 5. Seitenanzahl
|
|
|
|
|
page_count = get_sidebar_value('seiten') or get_sidebar_value('umfang')
|
|
|
|
|
if page_count:
|
|
|
|
|
match = re.search(r'\d+', page_count)
|
|
|
|
|
page_count = match.group(0) if match else "Unknown"
|
|
|
|
|
else:
|
|
|
|
|
page_count = "Unknown"
|
|
|
|
|
|
|
|
|
|
# 6. Beschreibung aus ID 'bookdesc' holen und Whitespace-Fluss säubern
|
|
|
|
|
description = "Keine Beschreibung verfügbar"
|
|
|
|
|
desc_div = soup.find(id='bookdesc')
|
|
|
|
|
if desc_div:
|
|
|
|
|
# Holt den Text inklusive aller Listenpunkte (li) und formatiert ihn sauber
|
|
|
|
|
description = " ".join(desc_div.text.split())
|
|
|
|
|
|
|
|
|
|
# 7. Cover-Bild (Nutzt hochauflösenden Link aus den Metas)
|
|
|
|
|
thumbnail = ""
|
|
|
|
|
img_meta = soup.find('meta', property='og:image')
|
|
|
|
|
if img_meta:
|
|
|
|
|
thumbnail = img_meta.get('content', '').strip()
|
|
|
|
|
else:
|
|
|
|
|
img_tag = soup.find('img', id='ISBNcover')
|
|
|
|
|
if img_tag:
|
|
|
|
|
thumbnail = img_tag.get('data-big') or img_tag.get('src')
|
|
|
|
|
|
|
|
|
|
if thumbnail and thumbnail.startswith('/'):
|
|
|
|
|
thumbnail = "https://www.isbn.de" + thumbnail
|
|
|
|
|
|
|
|
|
|
# 8. PREIS EXTRAHIEREN (Neu integriert)
|
|
|
|
|
price = None
|
|
|
|
|
# Option A: Aus dem standardisierten Meta-Tag extrahieren (Ergibt z.B. 12.25)
|
|
|
|
|
price_meta = soup.find('meta', property='product:price:amount')
|
|
|
|
|
if price_meta and price_meta.get('content'):
|
|
|
|
|
try:
|
|
|
|
|
price = float(price_meta.get('content').strip())
|
|
|
|
|
except ValueError:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
# Option B: Fallback über die Infotab-Sidebar (Falls Meta fehlt, filtert "12,25 €*" zu Float)
|
|
|
|
|
if price is None:
|
|
|
|
|
price_str = get_sidebar_value('preis')
|
|
|
|
|
if price_str:
|
|
|
|
|
# Findet Zahlen wie "12,25" oder "12.25"
|
|
|
|
|
match = re.search(r'\d+([.,]\d+)?', price_str)
|
|
|
|
|
if match:
|
|
|
|
|
try:
|
|
|
|
|
price = float(match.group(0).replace(',', '.'))
|
|
|
|
|
except ValueError:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
"title": title,
|
|
|
|
|
"authors": author,
|
|
|
|
|
"publisher": publisher,
|
|
|
|
|
"publishedDate": published_date,
|
|
|
|
|
"description": description,
|
|
|
|
|
"pageCount": page_count,
|
|
|
|
|
"price": price, # Gibt nun z.B. 12.25 als float zurück
|
|
|
|
|
"thumbnail": thumbnail,
|
|
|
|
|
"source": "isbn-de"
|
|
|
|
|
}
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(f"isbn.de Scraping error: {e}")
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
@app.route('/fetch_book_info/<isbn>')
|
|
|
|
|
def fetch_book_info(isbn):
|
|
|
|
|
"""
|
|
|
|
@@ -9562,6 +9694,7 @@ def fetch_book_info(isbn):
|
|
|
|
|
providers = [
|
|
|
|
|
_fetch_from_google_books,
|
|
|
|
|
_fetch_from_lobid_germany,
|
|
|
|
|
_fetch_from_isbn_de,
|
|
|
|
|
_fetch_from_open_library
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|