Add browser job capture to the job tracker
Deploy with Docker Compose / deploy (push) Successful in 1m31s

A Violentmonkey userscript, served by the site and installed from /cv/jobs,
adds the posting open in the browser (LinkedIn, an ATS, any company page) to
the tracker. Claude reads the title, company and location off the page text.

- Three token-guarded REST routes under /api/jobs/capture (status, extract,
  upsert). They take a bearer token, JOB_CAPTURE_TOKEN, because the auth
  cookies are SameSite=Lax and never sent from another origin. An unset token
  switches the routes off.
- The upsert matches on a canonical posting URL, then (company, job title),
  so a capture and the email pipeline do not make two rows for one job.
- The Claude call is a new internal Python route, /internal/jobs/extract,
  alongside the rowing reader; the client and fence stripping they share move
  to python/app/claude.py.
- New "saved" status ranked below "applied", and a description column holding
  the posting text, shown per row on the tracker.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-12 13:33:28 +01:00
co-authored by Claude Opus 5.5
parent 94eaa8e239
commit b8670246a8
28 changed files with 2003 additions and 145 deletions
+57 -8
View File
@@ -14,12 +14,15 @@ Endpoints
POST /hotels/search/stream same search, streamed as NDJSON
POST /hotels/scan/stream cheapest-night-in-a-range scan, NDJSON
POST /internal/rowing/read read a rowing display photo with Claude
(Go backend only - not reachable through nginx)
POST /internal/jobs/extract read a job posting's page text with Claude
(both: Go backend only - not reachable through
nginx)
All the hotel work lives in `travelodge`; this module is the HTTP skin around
it - request validation, a response cache, the one-search-at-a-time guard, and
the NDJSON framing. The rowing reader lives in `rowing` and is the one route
here that is not public: see the "Internal" section at the bottom. Consumed by vue/src/views/hotels/ (SingleStayPanel.vue,
the NDJSON framing. The rowing reader (`rowing`) and the job posting reader
(`jobs`) are the routes here that are not public: see the "Internal" sections
at the bottom. The hotel routes are consumed by vue/src/views/hotels/ (SingleStayPanel.vue,
CheapestNightPanel.vue, useHotelForm.js), which fetch these paths with the /py
prefix. Field names in the models below are part of that contract.
"""
@@ -35,7 +38,7 @@ from fastapi import FastAPI, HTTPException, Request
from fastapi.responses import StreamingResponse
from pydantic import BaseModel, Field, field_validator, model_validator
from . import rowing, travelodge
from . import jobs, rowing, travelodge
app = FastAPI(
title="Python API",
@@ -664,10 +667,10 @@ class RowingReadRequest(BaseModel):
def _internal_only(request: Request) -> None:
"""Refuse a request that arrived through nginx.
Every other route in this service is public, but this one spends a paid
Claude call per request and has no auth of its own - the admin check
happens in the Go backend, which calls this container directly over
app-network. Two layers keep the outside world off it, because either alone
Every other route in this service is public, but the internal ones spend
a paid Claude call per request and have no auth of their own - the admin
or token check happens in the Go backend, which calls this container
directly over app-network. Two layers keep the outside world off it, because either alone
is one config edit away from being lost:
1. nginx answers /py/internal/ with a 404 (both templates).
@@ -715,3 +718,49 @@ def rowing_read(req: RowingReadRequest, request: Request) -> rowing.RowingReadin
raise HTTPException(status_code=503, detail=str(e)) from None
except rowing.ReadError as e:
raise HTTPException(status_code=502, detail=str(e)) from None
# --------------------------------------------------------------------------- #
# Internal: job posting reader
# --------------------------------------------------------------------------- #
class JobExtractRequest(BaseModel):
"""A page for Claude to read, as the Go backend sends it."""
url: str = Field("", max_length=2000, description="The page's address; a hint for the model")
title: str = Field("", max_length=500, description="The page's <title>; a hint for the model")
text: str = Field(..., min_length=1, max_length=jobs.MAX_TEXT_CHARS, description="The page's visible text")
@app.post(
"/internal/jobs/extract",
response_model=jobs.JobPosting,
summary="Read the job title, company and location off a posting",
description=(
"Internal to the Go backend's token-guarded `POST /api/jobs/capture/extract`; not reachable "
"through nginx. Sends the page text to Claude and returns the fields it found. A page that is "
"not a job posting is a 200 with empty strings, not an error."
),
responses={
502: {"description": "Claude failed, or its reply was not the expected JSON"},
503: {"description": "CLAUDE_API_KEY is not set"},
},
)
def jobs_extract(req: JobExtractRequest, request: Request) -> jobs.JobPosting:
"""Read a job posting's page text.
A plain `def` for the same reason as `rowing_read`: the blocking Claude
call runs in the threadpool.
Raises:
HTTPException: 404 (came through nginx), 503 (no API key) or 502
(Claude failed or returned something unparseable). The 502 detail
is one of jobs.extract_posting's fixed messages, which the Go
handler passes on to the capture popup verbatim.
"""
_internal_only(request)
try:
return jobs.extract_posting(req.url, req.title, req.text)
except jobs.NotConfigured as e:
raise HTTPException(status_code=503, detail=str(e)) from None
except jobs.ReadError as e:
raise HTTPException(status_code=502, detail=str(e)) from None