Shelter PMS fully functional

This commit is contained in:
2024-12-09 16:36:11 +09:00
parent 60eaef5527
commit e76a80fb2f
47 changed files with 665 additions and 909 deletions

View File

@@ -3,11 +3,51 @@ from .base_plugin import BasePMSPlugin
class BnovoPMS(BasePMSPlugin):
"""
Плагин для интеграции с Bnovo.
"""
json_schema = {
"type": "object",
"properties": {
"id": {"type": "integer"},
"number": {"type": "integer"},
"roomTypeName": {"type": "string"},
"checkInStatus": {"type": "string"},
"guests": {"type": "array"},
},
"required": ["id", "number", "roomTypeName", "checkInStatus", "guests"]
}
def get_default_parser_settings(self):
"""
Возвращает настройки парсера по умолчанию.
"""
return {
"field_mapping": {
"room_name": "roomNumber",
"check_in": "from",
"check_out": "until",
},
"date_format": "%Y-%m-%dT%H:%M:%S"
}
def fetch_data(self):
response = requests.get(self.pms_config.url, headers={"Authorization": f"Bearer {self.pms_config.token}"})
response.raise_for_status()
data = response.json()
# Проверка структуры
expected_fields = self.pms_config.parser_settings.get("fields_mapping", {})
for field in expected_fields.values():
if field not in data[0]: # Проверяем первую запись
raise ValueError(f"Поле {field} отсутствует в ответе API.")
return data
def fetch_and_parse(self):
response = requests.get(
self.pms_config.url,
headers={"Authorization": f"Bearer {self.pms_config.token}"}
)
self.validate_response(response) # Проверка соответствия структуры
if response.status_code != 200:
raise ValueError(f"Ошибка запроса к PMS Bnovo: {response.text}")
@@ -28,3 +68,4 @@ class BnovoPMS(BasePMSPlugin):
}
reservations.append(reservation)
return reservations