diff --git a/app/app.py b/app/app.py index 6a68107..a1f8533 100644 --- a/app/app.py +++ b/app/app.py @@ -1,4 +1,4 @@ -import json, os, shutil, datetime, urllib.request +import json, os, shutil, datetime, urllib.request, urllib.parse from pathlib import Path from fastapi import FastAPI, Form from fastapi.responses import HTMLResponse, RedirectResponse @@ -16,6 +16,9 @@ LEADS = DATA / "leads.jsonl" EVENTS_LIVE = DATA / "events.json" EVENTS_SEED = Path(__file__).parent / "events.json" NTFY_URL = os.environ.get("NTFY_URL", "") +# Same lead pipeline as the flyer form (scouting73.thewichersfamily.com): +# forward /join posts to that container's /submit (Google Sheet + ntfy push). +FORM_UPSTREAM = os.environ.get("FORM_UPSTREAM", "http://scouting73-form:8000/submit") app = FastAPI(title="Pack & Troop 73") app.mount("/static", StaticFiles(directory="/app/static"), name="static") @@ -90,7 +93,7 @@ nav.links{display:flex;align-items:center;gap:26px;flex-wrap:wrap} nav.links a{text-decoration:none;font-weight:600;font-size:15px;color:#333D52;padding:6px 0} nav.links a:hover{color:#1E2F52} nav.links a.on{font-weight:700;color:#1E2F52;border-bottom:2px solid #F0AD2D} -a.joinbtn{font-family:'Archivo';font-weight:700;font-size:15px;background:#F0AD2D;color:#1E2F52 !important;padding:11px 22px;border-radius:999px;border-bottom:none !important} +a.joinbtn{display:inline-block;line-height:1.2;font-family:'Archivo';font-weight:700;font-size:15px;background:#F0AD2D;color:#1E2F52 !important;padding:11px 22px;border-radius:999px;border-bottom:none !important} a.joinbtn:hover{background:#DB9714} .hero{position:relative;display:flex;align-items:flex-end;min-height:520px} .hero .wrap{padding-top:110px;padding-bottom:58px;width:100%} @@ -499,14 +502,26 @@ def join_body(sent=False):
-
-
+
+
-
-
+
List all kids you're considering. Any grade K-12 welcome.
+
+ + +
We only use this to reply about Scouting. No newsletters, no sharing.
- + +
New-family FAQ

The questions every new family asks.

@@ -526,19 +541,46 @@ def contact_redirect(): @app.post("/join") def join_post(parent_name: str = Form(...), email: str = Form(...), phone: str = Form(""), - children: str = Form(""), program: str = Form(""), message: str = Form("")): + children: str = Form(""), interested_in: str = Form(""), source: str = Form(""), + source_place: str = Form(""), source_other: str = Form(""), message: str = Form("")): + if source == "Other school or daycare" and source_place.strip(): + source = "School/Daycare: " + source_place.strip() + elif source == "Other" and source_other.strip(): + source = "Other: " + source_other.strip() rec = {"ts": datetime.datetime.now().isoformat(timespec="seconds"), "parent_name": parent_name.strip(), "email": email.strip(), "phone": phone.strip(), - "children": children.strip(), "program": program.strip(), "message": message.strip()} + "children": children.strip(), "interested_in": interested_in.strip(), + "source": source.strip(), "message": message.strip()} try: with open(LEADS, "a", encoding="utf-8") as f: f.write(json.dumps(rec) + "\n") except Exception: pass - if NTFY_URL: + # Forward into the shared lead pipeline (Google Sheet + ntfy on the 'scouting' + # topic), same as scouting73.thewichersfamily.com. The comment rides along in + # the source column so it reaches the sheet and the phone push. + src = rec["source"] or "greenlanescouts73.org" + if rec["message"]: + src = src + " | Note: " + rec["message"][:300] + forwarded = False + try: + data = urllib.parse.urlencode({ + "parent_name": rec["parent_name"], "email": rec["email"], "phone": rec["phone"], + "children": rec["children"] or "(not given)", + "interested_in": rec["interested_in"] or "(not given)", "source": src, + }).encode() + rq = urllib.request.Request(FORM_UPSTREAM, data=data) + with urllib.request.urlopen(rq, timeout=6) as resp: + forwarded = resp.status < 400 + except Exception: + forwarded = False + if not forwarded and NTFY_URL: + # fallback push so a lead is never silently lost try: - b = ("New Scout interest: %s (%s) - %s" % (rec["parent_name"], rec["email"], rec["program"] or "program TBD")).encode() - rq = urllib.request.Request(NTFY_URL, data=b, headers={"Title": "greenlanescouts73.org lead", "Tags": "tent"}) + b = ("New Scout interest: %s (%s) - %s | Kids: %s | %s" % ( + rec["parent_name"], rec["email"], rec["interested_in"] or "program TBD", + rec["children"] or "?", src)).encode() + rq = urllib.request.Request(NTFY_URL, data=b, headers={"Title": "greenlanescouts73.org lead (sheet forward FAILED)", "Tags": "tent,warning"}) urllib.request.urlopen(rq, timeout=3) except Exception: pass