#!/bin/bash
SLUG="gabinet-masazu-piotr-czajkowski-kielce"
TITLE="Gabinet masażu Piotra Czajkowskiego w Kielcach – profesjonalne zabiegi"
IMG="https://adriangrabski.com/wp-content/uploads/2026/04/masazkielce.png"
DOMS=(aquacity.com.pl celebryciklub.pl driftworld.pl electroon.pl excambium.pl expertoo.pl fakturki24.pl gastrofaza-catering.pl gemstar.pl ideapv.pl chwilowki-online-bez-weryfikacji.pl)
DATES=(2026-05-05 2026-05-08 2026-05-11 2026-05-14 2026-05-17 2026-05-20 2026-05-23 2026-05-25 2026-05-27 2026-05-09 2026-05-15)
i=0
for d in "${DOMS[@]}"; do
P="/var/www/$d"; date="${DATES[$i]}"; i=$((i+1))
[ ! -f "$P/wp-config.php" ] && { echo "$d|NOWP||"; continue; }
WPU="sudo -u www-data wp --path=$P --allow-root --skip-themes --skip-plugins"
EX=$($WPU post list --post_type=post --name="$SLUG" --field=ID 2>/dev/null | head -1)
[ -n "$EX" ] && { echo "$d|EXISTS|$EX|https://$d/$SLUG/"; continue; }
HTML=$(python3 -c "import json;print(json.load(open('/tmp/bm_articles3.json'))['$d'])" 2>/dev/null)
[ -z "$HTML" ] && { echo "$d|NOHTML||"; continue; }
PID=$($WPU post create --post_type=post --post_status=publish --post_title="$TITLE" --post_name="$SLUG" --post_date="$date 10:00:00" --post_content="$HTML" --porcelain 2>/dev/null | tail -1)
[ -z "$PID" ] && { echo "$d|FAIL||"; continue; }
$WPU media import "$IMG" --post_id=$PID --featured_image >/dev/null 2>&1
CAT=$($WPU term list category --field=term_id --number=1 2>/dev/null | head -1)
[ -n "$CAT" ] && $WPU post term set $PID category $CAT >/dev/null 2>&1
$WPU rewrite flush >/dev/null 2>&1
echo "$d|OK|$PID|https://$d/$SLUG/"
done