refactor(webrequest): linting, docstrings
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
"""A dataclass representing book data from the library system and catalogue."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any
|
||||
@@ -7,6 +11,15 @@ import regex
|
||||
|
||||
@dataclass
|
||||
class BookData:
|
||||
"""A dataclass representing the book object.
|
||||
|
||||
Returns
|
||||
-------
|
||||
self : BookData
|
||||
The book data object with attributes like title, author, year, etc.
|
||||
|
||||
"""
|
||||
|
||||
ppn: str | None = None
|
||||
title: str | None = None
|
||||
signature: str | None = None
|
||||
@@ -14,7 +27,7 @@ class BookData:
|
||||
link: str | None = None
|
||||
isbn: str | list[str] | None = field(default_factory=list[str])
|
||||
author: str | None = None
|
||||
language: str | list[str] | None = field(default_factory=list)
|
||||
language: str | list[str] | None = field(default_factory=list[str])
|
||||
publisher: str | None = None
|
||||
place: str | None = None
|
||||
year: int | None = None
|
||||
@@ -25,10 +38,11 @@ class BookData:
|
||||
old_book: Any | None = None
|
||||
media_type: str | None = None
|
||||
in_library: bool | None = None # whether the book is in the library or not
|
||||
libraries: list[str] | None = field(default_factory=list)
|
||||
libraries: list[str] | None = field(default_factory=list[str])
|
||||
medianr: int | None = None # media number
|
||||
|
||||
def __post_init__(self):
|
||||
def __post_init__(self) -> None:
|
||||
"""Run Post-initialization processing."""
|
||||
self.library_location = (
|
||||
str(self.library_location) if self.library_location else None
|
||||
)
|
||||
@@ -38,12 +52,12 @@ class BookData:
|
||||
self.year = regex.sub(r"[^\d]", "", str(self.year)) if self.year else None
|
||||
self.in_library = True if self.signature else False
|
||||
|
||||
def from_dict(self, data: dict) -> "BookData":
|
||||
def from_dict(self, data: dict[str, Any]) -> BookData:
|
||||
for key, value in data.items():
|
||||
setattr(self, key, value)
|
||||
return self
|
||||
|
||||
def merge(self, other: "BookData") -> "BookData":
|
||||
def merge(self, other: BookData) -> BookData:
|
||||
for key, value in other.__dict__.items():
|
||||
# merge lists, if the attribute is a list, extend it
|
||||
if isinstance(value, list):
|
||||
@@ -89,12 +103,12 @@ class BookData:
|
||||
return "Druckausgabe"
|
||||
return None
|
||||
|
||||
def from_string(self, data: str) -> "BookData":
|
||||
def from_string(self, data: str) -> BookData:
|
||||
ndata = json.loads(data)
|
||||
|
||||
return BookData(**ndata)
|
||||
|
||||
def from_LehmannsSearchResult(self, result: Any) -> "BookData":
|
||||
def from_LehmannsSearchResult(self, result: Any) -> BookData:
|
||||
self.title = result.title
|
||||
self.author = "; ".join(result.authors) if result.authors else None
|
||||
self.edition = str(result.edition) if result.edition else None
|
||||
|
||||
Reference in New Issue
Block a user