pms_integration in process
This commit is contained in:
@@ -1,31 +1,30 @@
|
||||
# pms_integration/plugins/example_pms.py
|
||||
|
||||
import requests
|
||||
from .base_plugin import BasePMSPlugin
|
||||
|
||||
class ExamplePMSPlugin(BasePMSPlugin):
|
||||
"""Плагин для интеграции с Example PMS."""
|
||||
|
||||
def fetch_data(self):
|
||||
"""Получение данных от Example PMS."""
|
||||
url = self.api_config.url
|
||||
headers = {"Authorization": f"Bearer {self.api_config.token}"}
|
||||
response = requests.get(url, headers=headers, timeout=10)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
class BnovoPMS(BasePMSPlugin):
|
||||
def fetch_and_parse(self):
|
||||
response = requests.get(
|
||||
self.pms_config.url,
|
||||
headers={"Authorization": f"Bearer {self.pms_config.token}"}
|
||||
)
|
||||
if response.status_code != 200:
|
||||
raise ValueError(f"Ошибка запроса к PMS Bnovo: {response.text}")
|
||||
|
||||
def parse_data(self, raw_data):
|
||||
"""Обработка данных от Example PMS."""
|
||||
reservations = raw_data.get("reservations", [])
|
||||
return [
|
||||
{
|
||||
"id": res["id"],
|
||||
"room_number": res["room_number"],
|
||||
"room_type": res["room_type"],
|
||||
"check_in": res["check_in"],
|
||||
"check_out": res["check_out"],
|
||||
"status": res["status"],
|
||||
"price": res.get("price"),
|
||||
data = response.json()
|
||||
parsed_data = self.parse_data(data)
|
||||
return parsed_data
|
||||
|
||||
def parse_data(self, data):
|
||||
# Пример разбора данных на основе JSON-маски
|
||||
reservations = []
|
||||
for item in data["reservations"]:
|
||||
reservation = {
|
||||
"id": item["id"],
|
||||
"room_number": item["roomNumber"],
|
||||
"check_in": item["checkIn"],
|
||||
"check_out": item["checkOut"],
|
||||
"status": item["status"],
|
||||
}
|
||||
for res in reservations
|
||||
]
|
||||
reservations.append(reservation)
|
||||
return reservations
|
||||
|
||||
Reference in New Issue
Block a user