119 lines
9.4 KiB
Python
119 lines
9.4 KiB
Python
import re
|
||
|
||
print("Aligning VIP room fields and fixing rendering in live_marketing_index.html...")
|
||
|
||
with open('/workspace/live_marketing_index.html', 'r', encoding='utf-8') as f:
|
||
html = f.read()
|
||
|
||
# Replace the VIP card mapping section in renderGoogleAdsB2BView
|
||
old_vip_map = """ <div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px;">
|
||
${data.vip_rooms.map(room => {
|
||
let isCrit = room.status === 'critical';
|
||
let isWarn = room.status === 'warning';
|
||
let badgeBg = isCrit ? '#FFE4E6' : (isWarn ? '#FEF3C7' : '#DCFCE7');
|
||
let badgeColor = isCrit ? '#9F1239' : (isWarn ? '#92400E' : '#166534');
|
||
let badgeText = isCrit ? '⚠️ بحرانی (فاصله زیاد از تارگت)' : (isWarn ? '⚡ نیازمند توجه' : '✅ در مسیر تارگت');
|
||
|
||
return `
|
||
<div style="border: 1.5px solid ${isCrit ? '#FDA4AF' : (isWarn ? '#FDE68A' : '#BBF7D0')}; background: var(--bg-card); border-radius: 14px; padding: 16px; box-shadow: 0 2px 8px rgba(0,0,0,0.02);">
|
||
<div style="display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px;">
|
||
<div>
|
||
<div style="font-weight: 800; font-size: 0.95rem; color: var(--text-main);">${room.room_name}</div>
|
||
<div style="font-size: 0.75rem; color: var(--text-muted);">${room.genre} | ظرفیت: ${room.capacity_per_slot} نفر</div>
|
||
</div>
|
||
<span style="background: ${badgeBg}; color: ${badgeColor}; font-size: 0.72rem; font-weight: 800; padding: 3px 8px; border-radius: 6px;">${badgeText}</span>
|
||
</div>
|
||
|
||
<div style="display: flex; justify-content: space-between; margin-bottom: 6px; font-size: 0.78rem;">
|
||
<span style="color: var(--text-muted);">رزرو شده: <strong>${room.booked_slots}</strong> از ${room.target_slots} سانس</span>
|
||
<span style="font-weight: 800; color: ${isCrit ? '#E11D48' : '#059669'};">${room.completion_pct}%</span>
|
||
</div>
|
||
|
||
<div style="height: 7px; background: var(--bg-body); border-radius: 4px; overflow: hidden; margin-bottom: 12px;">
|
||
<div style="height: 100%; width: ${room.completion_pct}%; background: ${isCrit ? '#E11D48' : (isWarn ? '#F59E0B' : '#10B981')}; border-radius: 4px;"></div>
|
||
</div>
|
||
|
||
<div style="background: var(--bg-body); padding: 8px 10px; border-radius: 8px; font-size: 0.75rem; line-height: 1.5; color: var(--text-body); margin-bottom: 12px;">
|
||
💡 <strong>اکشن فوری سوشال:</strong> ${room.suggested_rescue_action}
|
||
</div>
|
||
|
||
<div style="display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--border-color); padding-top: 10px;">
|
||
<span style="font-size: 0.75rem; font-weight: 700; color: var(--primary);">قیمت بلیت: ${room.ticket_price_toman.toLocaleString('fa-IR')} تومان</span>
|
||
<button onclick="createScenarioForRescue('${room.room_name.replace(/'/g, "\\\\'")}', '${room.suggested_rescue_action.replace(/'/g, "\\\\'")}')" class="date-btn active" style="padding: 4px 10px; font-size: 0.72rem; background: var(--primary); color: #fff;">
|
||
➕ ایجاد سناریو در شیت
|
||
</button>
|
||
</div>
|
||
</div>
|
||
`;
|
||
}).join('')}
|
||
</div>"""
|
||
|
||
new_vip_map = """ <div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px;">
|
||
${data.vip_rooms.map(room => {
|
||
let isCrit = room.status === 'critical';
|
||
let isWarn = room.status === 'warning';
|
||
let badgeBg = isCrit ? '#FFE4E6' : (isWarn ? '#FEF3C7' : '#DCFCE7');
|
||
let badgeColor = isCrit ? '#9F1239' : (isWarn ? '#92400E' : '#166534');
|
||
let badgeText = isCrit ? '⚠️ بحرانی (فاصله زیاد از تارگت)' : (isWarn ? '⚡ نیازمند توجه' : '✅ در مسیر تارگت');
|
||
|
||
const rName = room.name || room.room_name || 'اتاق VIP';
|
||
const rCat = room.category || room.genre || 'سینما فرار / ترس';
|
||
const rBooked = room.booked !== undefined ? room.booked : (room.booked_slots || 0);
|
||
const rTarget = room.monthly_target !== undefined ? room.monthly_target : (room.target_slots || 0);
|
||
const rPct = room.achievement_pct !== undefined ? room.achievement_pct : (room.completion_pct || 0);
|
||
const rPrice = room.price_per_slot || (room.ticket_price_toman ? room.ticket_price_toman.toLocaleString('fa-IR') + ' تومان' : '۱,۶۰۰,۰۰۰ تومان');
|
||
const rAction = room.suggested_action || room.suggested_rescue_action || 'اجرای سناریو و ریلز تبلیغاتی';
|
||
|
||
return `
|
||
<div style="border: 1.5px solid ${isCrit ? '#FDA4AF' : (isWarn ? '#FDE68A' : '#BBF7D0')}; background: var(--bg-card); border-radius: 14px; padding: 16px; box-shadow: 0 2px 8px rgba(0,0,0,0.02);">
|
||
<div style="display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px;">
|
||
<div>
|
||
<div style="font-weight: 800; font-size: 0.95rem; color: var(--text-main);">${rName}</div>
|
||
<div style="font-size: 0.75rem; color: var(--text-muted);">${rCat}</div>
|
||
</div>
|
||
<span style="background: ${badgeBg}; color: ${badgeColor}; font-size: 0.72rem; font-weight: 800; padding: 3px 8px; border-radius: 6px;">${badgeText}</span>
|
||
</div>
|
||
|
||
<div style="display: flex; justify-content: space-between; margin-bottom: 6px; font-size: 0.78rem;">
|
||
<span style="color: var(--text-muted);">رزرو شده: <strong>${rBooked}</strong> از ${rTarget} سانس</span>
|
||
<span style="font-weight: 800; color: ${isCrit ? '#E11D48' : '#059669'}; font-feature-settings: 'tnum';">${rPct}%</span>
|
||
</div>
|
||
|
||
<div style="height: 7px; background: var(--bg-body); border-radius: 4px; overflow: hidden; margin-bottom: 12px;">
|
||
<div style="height: 100%; width: ${Math.min(rPct, 100)}%; background: ${isCrit ? '#E11D48' : (isWarn ? '#F59E0B' : '#10B981')}; border-radius: 4px;"></div>
|
||
</div>
|
||
|
||
<div style="background: var(--bg-body); padding: 8px 10px; border-radius: 8px; font-size: 0.75rem; line-height: 1.5; color: var(--text-body); margin-bottom: 12px;">
|
||
💡 <strong>اکشن فوری سوشال:</strong> ${rAction}
|
||
</div>
|
||
|
||
<div style="display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--border-color); padding-top: 10px;">
|
||
<span style="font-size: 0.75rem; font-weight: 700; color: var(--primary);">قیمت هر سانس: ${rPrice}</span>
|
||
<button onclick="createScenarioForRescue('${rName.replace(/'/g, "\\\\'")}', '${rAction.replace(/'/g, "\\\\'")}')" class="date-btn active" style="padding: 4px 10px; font-size: 0.72rem; background: var(--primary); color: #fff;">
|
||
➕ ایجاد سناریو در شیت
|
||
</button>
|
||
</div>
|
||
</div>
|
||
`;
|
||
}).join('')}
|
||
</div>"""
|
||
|
||
# Replace in html
|
||
if old_vip_map in html:
|
||
html = html.replace(old_vip_map, new_vip_map)
|
||
print("Directly replaced VIP card map!")
|
||
else:
|
||
# Fuzzy replace
|
||
start_v = html.find('<!-- SECTION 1: VIP ROOMS SALES WARNING & RESCUE ENGINE -->')
|
||
end_v = html.find('<!-- SECTION 2: B2B CORPORATE PACKAGES -->')
|
||
if start_v != -1 and end_v != -1:
|
||
sec1_block = html[start_v:end_v]
|
||
# Replace the mapping
|
||
re_vip = re.sub(r'\$\{data\.vip_rooms\.map[\s\S]*?\}\.join\(\'\'\)\}', new_vip_map.strip(), sec1_block)
|
||
html = html[:start_v] + re_vip + html[end_v:]
|
||
print("Replaced VIP section with regex!")
|
||
|
||
with open('/workspace/live_marketing_index.html', 'w', encoding='utf-8') as f:
|
||
f.write(html)
|
||
|
||
print("Saved updated live_marketing_index.html with bulletproof VIP cards!")
|