mirror of
https://github.com/Noettore/lagomareGateKeeperBot.git
synced 2025-10-15 19:46:40 +02:00
Che schifo
This commit is contained in:
21
repository/gates_repository.py
Normal file
21
repository/gates_repository.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import json
|
||||
from models import Status, Gate
|
||||
|
||||
class GatesRepository:
|
||||
def __init__(self, json_path: str = "./data/gates.json"):
|
||||
self._json_path: str = json_path
|
||||
self._gates: dict[str, Gate] = self._load_gates()
|
||||
|
||||
def _load_gates(self) -> dict[str, Gate]:
|
||||
try:
|
||||
with open(self._json_path, "r") as file:
|
||||
gates_data = json.load(file)
|
||||
return {gate: Gate.from_dict(data) for gate, data in gates_data.items()}
|
||||
except Exception:
|
||||
return {}
|
||||
|
||||
def get_by_key(self, key: str) -> Gate | None:
|
||||
return self._gates[key] if key in self._gates else None
|
||||
|
||||
def get_all_gates_id(self) -> list[str]:
|
||||
return [gate for gate in self._gates.keys() if self._gates[gate].status == Status.ENABLED]
|
Reference in New Issue
Block a user