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
|
||||
|
||||
|
||||
class StorageAdapter(ABC):
|
||||
"""Abstrakte Basisklasse für POI-Storage-Backends."""
|
||||
class StorageWriter(ABC):
|
||||
"""Write-only Interface. Klassen MÜSSEN explizit erben."""
|
||||
|
||||
@abstractmethod
|
||||
def store(self, results: list[POI]) -> str:
|
||||
@ -27,30 +27,32 @@ class StorageAdapter(ABC):
|
||||
Returns:
|
||||
str: Identifier der gespeicherten Ressource
|
||||
(Dateipfad, DB-Tabelle, URL, etc.)
|
||||
|
||||
Raises:
|
||||
StorageError: Bei Schreibfehlern.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class JsonStorage(StorageAdapter):
|
||||
class JsonStorage(StorageWriter):
|
||||
"""
|
||||
"""
|
||||
def __init__(self, output_dir: Path = Path(".")):
|
||||
self.output_dir = output_dir
|
||||
self._path = self.output_dir / "pois.json"
|
||||
|
||||
def store(self, results: list[POI]) -> str:
|
||||
output_path = self.output_dir / "pois.json"
|
||||
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)
|
||||
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
|
||||
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"):
|
||||
pass
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user