"""Insert chat invitation + discount blocks into Listmonk campaigns.""" import json import subprocess API_USER = "api" API_PASS = "6X1rKPea61N4rZ1S65Hx5zvqzbCj30F6nvEe9oVGH_Y" LISTMONK = "http://localhost:9100" DISCOUNT = '
Split it into 4 payments: Pay ~$975/month with Klarna Pay in 4. Start your Canadian carrier setup today — pay over time.
' CHAT = '
Questions? We\'re online.
Chat with us live on our website (look for the chat icon in the bottom-right), or call 1-888-411-0383.
' FOOTER_MARKER = 'style="display:block;margin:0 auto 10px;width:70px' def api_get(path): r = subprocess.run(["curl", "-s", "-u", f"{API_USER}:{API_PASS}", f"{LISTMONK}{path}"], capture_output=True, text=True, timeout=10) return json.loads(r.stdout) def api_put(path, data): r = subprocess.run(["curl", "-s", "-X", "PUT", "-u", f"{API_USER}:{API_PASS}", "-H", "Content-Type: application/json", "-d", json.dumps(data), f"{LISTMONK}{path}"], capture_output=True, text=True, timeout=10) return json.loads(r.stdout) if r.stdout else {} # Campaigns that need discount + chat (final close emails) DISCOUNT_CAMPAIGNS = [12, 18] # Campaigns that need only chat CHAT_CAMPAIGNS = [9, 10, 11, 15, 16, 17, 22, 23] for cid in DISCOUNT_CAMPAIGNS + CHAT_CAMPAIGNS: d = api_get(f"/api/campaigns/{cid}") body = d["data"]["body"] name = d["data"]["name"] add_discount = cid in DISCOUNT_CAMPAIGNS if "We're online" in body or "We are online" in body: print(f" SKIP {cid:3d} | {name[:55]} | already has chat block") continue if FOOTER_MARKER not in body: print(f" SKIP {cid:3d} | {name[:55]} | no footer marker") continue idx = body.index(FOOTER_MARKER) tr_start = body[:idx].rfind("