Compare commits
3 Commits
c09a822fec
...
82fe7f2939
| Author | SHA1 | Date | |
|---|---|---|---|
| 82fe7f2939 | |||
| c39dd9c625 | |||
| 51c372d4ab |
20
storage.py
20
storage.py
@ -13,8 +13,8 @@ class StorageError(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class StorageAdapter(ABC):
|
class StorageWriter(ABC):
|
||||||
"""Abstrakte Basisklasse für POI-Storage-Backends."""
|
"""Write-only Interface. Klassen MÜSSEN explizit erben."""
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def store(self, results: list[POI]) -> str:
|
def store(self, results: list[POI]) -> str:
|
||||||
@ -27,30 +27,32 @@ class StorageAdapter(ABC):
|
|||||||
Returns:
|
Returns:
|
||||||
str: Identifier der gespeicherten Ressource
|
str: Identifier der gespeicherten Ressource
|
||||||
(Dateipfad, DB-Tabelle, URL, etc.)
|
(Dateipfad, DB-Tabelle, URL, etc.)
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
StorageError: Bei Schreibfehlern.
|
StorageError: Bei Schreibfehlern.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
class JsonStorage(StorageAdapter):
|
class JsonStorage(StorageWriter):
|
||||||
|
"""
|
||||||
|
"""
|
||||||
def __init__(self, output_dir: Path = Path(".")):
|
def __init__(self, output_dir: Path = Path(".")):
|
||||||
self.output_dir = output_dir
|
self.output_dir = output_dir
|
||||||
|
self._path = self.output_dir / "pois.json"
|
||||||
|
|
||||||
def store(self, results: list[POI]) -> str:
|
def store(self, results: list[POI]) -> str:
|
||||||
output_path = self.output_dir / "pois.json"
|
|
||||||
try:
|
try:
|
||||||
with output_path.open("w", encoding="utf-8") as f:
|
with self._path.open("w", encoding="utf-8") as f:
|
||||||
json.dump([asdict(poi) for poi in results], f, indent=2, ensure_ascii=False)
|
json.dump([asdict(poi) for poi in results], f, indent=2, ensure_ascii=False)
|
||||||
except OSError as exc:
|
except OSError as exc:
|
||||||
logger.error(f"Fehler beim Speichern:{exc}")
|
logger.error(f"Fehler beim Speichern: {exc}")
|
||||||
raise StorageError("Fehler beim Speichern der POIs") from exc
|
raise StorageError("Fehler beim Speichern der POIs") from exc
|
||||||
return str(output_path.resolve())
|
return str(self._path.resolve())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class PostgresStorage(StorageAdapter):
|
class PostgresStorage(StorageWriter):
|
||||||
|
|
||||||
def __init__(self, connection_string: str, table: str = "pois"):
|
def __init__(self, connection_string: str, table: str = "pois"):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user