The homepage was a bare tool: a find-bar and an empty panel reading "Find a location to begin." A visitor arriving from a search result or a shared link learned nothing about what the product does before deciding to leave. Rebuild it around the Weekly view, which is untouched: - Hero with the question as the h1, and a grade card showing a real graded example — the most unusual city we're currently tracking, either tail. The card's frame and text slots are server-rendered with reserved heights, so app.js re-pointing it at the visitor's own place shifts nothing. - "Unusual right now" strip, CSS scroll-snap, no JS carousel. A cold-tail city is force-included whenever one qualifies. - Stance line, how-it-works, explore cards, and 12 city chips linking into the ~1000-page /climate surface. - Monthly digest form, in the footer of every page. Serve / from Jinja instead of a static file with placeholder substitution, so crawlers and no-JS readers get the whole page as real HTML. home.html.j2 extends base.html.j2 and carries app.js's DOM contract over verbatim; the brand degrades to a <p> so the hero owns the sole h1. frontend/index.html is deleted rather than left behind the static mount, where it would keep serving indexable duplicate content. "Where is it most unusual right now" has no cheap answer at request time — percentiles live inside zlib-compressed payload blobs with no column to sort on. So homepage.py sweeps the warm cache and writes data/homepage.json, read by the template. The sweep is strictly cache-only (climate.load_cached_recent_forecast is new, the sibling of load_cached_history), so grading ~1000 cities costs zero upstream requests. It rides the notifier's timer behind an hourly guard rather than starting a second daemon, and also runs at the tail of warm_cities so a fresh deploy has a populated feed. Instrumentation: metrics gains a product-event counter keyed by (event, referrer domain, UTC day), behind an allowlist and a per-IP rate limit, fed by POST /api/v2/event. The referrer is taken from the request's own header, never from the client. The beacon gets its own inbound category that record_inbound ignores, so reporting an interaction doesn't also count as traffic. The dashboard grows an events block with per-referrer attribution. Email is scaffolded but sends nothing yet. mailer.py talks stdlib smtplib to a local Postfix null client on 127.0.0.1:25 (deploy/provision-mail.sh), so the choice between direct-to-MX and relaying through a provider stays a Postfix config change with no code change. The backend defaults to "console", which logs and sends nothing, so dev and tests exercise the whole signup path safely. Signups land in pending_digest unconfirmed; collecting the list shouldn't wait on delivery. Also adds /privacy, linked from the footer and kept out of the sitemap. The strip's classes are named unusual-* rather than record-*: .record-card is already the SEO records page's, and reusing it leaked layout rules onto /climate/<slug>/records.
59 lines
2.4 KiB
Python
59 lines
2.4 KiB
Python
"""Pre-warm the archives for the curated city set (backend/cities.json) so the
|
|
crawlable /climate pages render from cache and a search-engine crawl never bursts
|
|
the archive API quota. Run at/after deploy:
|
|
|
|
python warm_cities.py [--limit N] [--pace SECONDS]
|
|
|
|
Idempotent: a cell whose archive is already cached is skipped. Fetches are paced
|
|
(default 2s) to stay well under the archive API's rate limit. A cell that still
|
|
has no cached archive when its page is first requested self-heals via get_history,
|
|
so this is an optimization, not a hard dependency.
|
|
"""
|
|
import sys
|
|
import time
|
|
|
|
import cities
|
|
import climate
|
|
import grid
|
|
import homepage
|
|
|
|
|
|
def main(limit: int | None = None, pace: float = 2.0) -> None:
|
|
todo = cities.all_cities()
|
|
if limit:
|
|
todo = todo[:limit]
|
|
fetched = skipped = failed = 0
|
|
for i, c in enumerate(todo, 1):
|
|
cell = grid.snap(c["lat"], c["lon"])
|
|
cached = climate.load_cached_history(cell)
|
|
if cached is not None and not cached.is_empty():
|
|
skipped += 1
|
|
continue
|
|
try:
|
|
climate.get_history(cell) # fetch + cache the ~45-yr archive
|
|
climate.get_recent_forecast(cell) # + the recent/forecast bundle (today block)
|
|
fetched += 1
|
|
print(f"[{i}/{len(todo)}] warmed {c['slug']} ({cell['id']})")
|
|
time.sleep(pace)
|
|
except Exception as e: # noqa: BLE001 - keep going; the page self-heals later
|
|
failed += 1
|
|
print(f"[{i}/{len(todo)}] FAILED {c['slug']}: {e}")
|
|
time.sleep(pace)
|
|
print(f"done: fetched={fetched} skipped(cached)={skipped} failed={failed}")
|
|
|
|
# Rebuild the homepage's "unusual right now" feed from whatever is now warm.
|
|
# Runs here as well as on the notifier loop so a fresh deploy has a populated
|
|
# feed immediately, and so it still refreshes when the notifier is disabled.
|
|
try:
|
|
feed = homepage.refresh()
|
|
print(f"homepage feed: {feed['considered']} cities graded, "
|
|
f"{len(feed['ranked'])} ranked")
|
|
except Exception as e: # noqa: BLE001 - the homepage renders without the feed
|
|
print(f"homepage feed: FAILED {e}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
args = sys.argv[1:]
|
|
lim = int(args[args.index("--limit") + 1]) if "--limit" in args else None
|
|
pc = float(args[args.index("--pace") + 1]) if "--pace" in args else 2.0
|
|
main(limit=lim, pace=pc)
|