| Server IP : 216.92.14.13 / Your IP : 216.73.217.126 Web Server : Apache System : Linux vps4089.pairvps.com 5.15.0-190-generic #200-Ubuntu SMP Fri Aug 7 15:06:04 UTC 2026 x86_64 User : rmlac2fmr ( 1040637) PHP Version : 8.2.32 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/home/rmlac2fmr/ |
Upload File : |
#!/usr/bin/env python3
"""
Remove redundant, DATE-LESS hotel booking stubs for the ACF show (S3).
A "stub" here is an assigned hotel booking that has NO check-in/check-out
date. It is only removed when the SAME person already has another assigned
booking for the same show that DOES have dates (the real booking). People
with a single booking, or with two legitimate dated bookings (e.g. a NJ stay
then a DC stay), are never touched.
Safety:
- Writes a timestamped backup of db.json before changing anything.
- Read-then-remove only; never edits the surviving booking.
- Prints exactly what it removed and what it kept.
- Idempotent: safe to run more than once.
After running: restart the app, then hard-refresh all open tabs.
Run: python3 ~/cleanup_acf_hotel_stubs.py
"""
import json, os, shutil, datetime
DB_PATH = os.path.expanduser("~/public_html/jn.com/ops/data/db.json")
SHOW = "S3" # ACF only, per request
def blank(v):
return v is None or str(v).strip() == ""
# --- backup first ---
stamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
backup = f"{DB_PATH}.bak.{stamp}"
shutil.copy2(DB_PATH, backup)
print(f"Backup written: {backup}\n")
with open(DB_PATH, "r", encoding="utf-8") as f:
db = json.load(f)
bookings = db.get("hotelBookings", [])
# Group this show's bookings by person
by_person = {}
for h in bookings:
if h.get("showId") != SHOW:
continue
by_person.setdefault(h.get("personId"), []).append(h)
remove_ids = set()
report = [] # (name, kept_id, removed_id)
def name_of(hbs):
for h in hbs:
nm = f"{(h.get('lastName') or '').strip()}, {(h.get('firstName') or '').strip()}".strip(", ")
if nm:
return nm
return "(no name)"
for pid, hbs in by_person.items():
assigned = [h for h in hbs if h.get("assigned")]
dated = [h for h in assigned if not blank(h.get("checkIn")) and not blank(h.get("checkOut"))]
dateless = [h for h in assigned if blank(h.get("checkIn")) or blank(h.get("checkOut"))]
# Only remove a date-less stub if a real DATED booking exists for this person
if dated and dateless:
keep_id = dated[0].get("id")
for stub in dateless:
remove_ids.add(stub.get("id"))
report.append((name_of(hbs), keep_id, stub.get("id"),
stub.get("hotel"), stub.get("checkIn"), stub.get("checkOut")))
before = len(db["hotelBookings"])
db["hotelBookings"] = [h for h in db["hotelBookings"] if h.get("id") not in remove_ids]
after = len(db["hotelBookings"])
with open(DB_PATH, "w", encoding="utf-8") as f:
json.dump(db, f, indent=2)
print(f"=== ACF (S3) date-less hotel stub cleanup ===")
print(f"Stubs removed: {len(remove_ids)} ({before - after} record(s) deleted)\n")
if not report:
print(" (none found — nothing to remove)")
for nm, keep_id, rm_id, hotel, ci, co in report:
print(f" {nm}")
print(f" KEPT booking {keep_id}")
print(f" REMOVED booking {rm_id} (hotel={hotel!r}, checkIn={ci!r}, checkOut={co!r})")
print()
print("Done. Restart the app, then hard-refresh all open tabs.")