From 491940496d0f364255187ef0ffddec27c2685f4e Mon Sep 17 00:00:00 2001 From: OpenClaw Assistant Date: Sat, 21 Feb 2026 18:59:58 +0000 Subject: [PATCH] Auto-sync paradiz human price files into prices.csv --- scripts/sync-paradiz-prices.sh | 89 ++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100755 scripts/sync-paradiz-prices.sh diff --git a/scripts/sync-paradiz-prices.sh b/scripts/sync-paradiz-prices.sh new file mode 100755 index 0000000..6957755 --- /dev/null +++ b/scripts/sync-paradiz-prices.sh @@ -0,0 +1,89 @@ +#!/usr/bin/env bash +set -euo pipefail + +BASE="/home/openclaw/.openclaw/workspace/skills/paradiz/references" +STATE_DIR="/home/openclaw/.openclaw/workspace/.openclaw" +STATE_FILE="$STATE_DIR/paradiz-prices-sync.state" +OUT_FILE="$BASE/prices.csv" +mkdir -p "$STATE_DIR" + +python3 - <<'PY' +import csv +import glob +import hashlib +import os +from pathlib import Path + +base = Path('/home/openclaw/.openclaw/workspace/skills/paradiz/references') +state_file = Path('/home/openclaw/.openclaw/workspace/.openclaw/paradiz-prices-sync.state') +out_file = base / 'prices.csv' + +candidates = sorted(glob.glob(str(base / 'prices_human_*.csv')), key=lambda p: os.path.getmtime(p), reverse=True) +if not candidates: + raise SystemExit(0) + +src = Path(candidates[0]) # берём самый свежий human-файл +raw = src.read_bytes() +sig = hashlib.sha256(raw).hexdigest() +if state_file.exists() and state_file.read_text(encoding='utf-8').strip() == sig: + raise SystemExit(0) + +rows = None +for enc in ('utf-8-sig', 'cp1251', 'utf-8'): + try: + txt = raw.decode(enc) + reader = csv.DictReader(txt.splitlines(), delimiter=';') + rows = list(reader) + if reader.fieldnames: + break + except Exception: + continue + +if rows is None: + raise SystemExit(0) + +# русские -> канонические поля prices.csv +mapping = { + 'Тип номера': 'room', + 'Период с': 'date_from', + 'Период по': 'date_to', + 'Гостей от': 'guests_min', + 'Гостей до': 'guests_max', + 'Питание': 'meal', + 'Цена за ночь': 'price_per_night', + 'Валюта': 'currency', + 'Примечание': 'notes', +} + +fields = ['date_from','date_to','guests_min','guests_max','room','meal','price_per_night','currency','notes'] + +normalized = [] +for r in rows: + if not r: + continue + item = {k: '' for k in fields} + for ru, canon in mapping.items(): + item[canon] = (r.get(ru, '') or '').strip() + + # cleanup + if item['currency'].upper() == 'RUB': + item['currency'] = '₽' + if item['price_per_night'].endswith(' руб.'): + item['price_per_night'] = item['price_per_night'].replace(' руб.', '').strip() + + # пропускаем пустые строки + if not item['room'] or not item['date_from'] or not item['date_to'] or not item['price_per_night']: + continue + normalized.append(item) + +if not normalized: + raise SystemExit(0) + +with out_file.open('w', encoding='utf-8', newline='') as f: + w = csv.DictWriter(f, fieldnames=fields) + w.writeheader() + w.writerows(normalized) + +state_file.write_text(sig, encoding='utf-8') +print(f'synced from {src.name}: {len(normalized)} rows') +PY