Use Zillow parcel hints for CAD lookup

This commit is contained in:
2026-03-28 03:55:56 -05:00
parent ece8fc548f
commit b77134ced5
11 changed files with 438 additions and 18 deletions

View File

@@ -58,6 +58,92 @@ export function extractZillowStructuredPhotoCandidatesFromNextDataScript(scriptT
return out;
}
function collapseIdentifier(value) {
return String(value || "").replace(/\s+/g, " ").trim();
}
function isLikelyIdentifier(value) {
return /^[A-Z0-9-]{4,40}$/i.test(collapseIdentifier(value));
}
function visitForIdentifierHints(node, hints) {
if (!node || typeof node !== "object") return;
if (Array.isArray(node)) {
for (const item of node) {
visitForIdentifierHints(item, hints);
}
return;
}
for (const [key, value] of Object.entries(node)) {
const normalizedKey = key.toLowerCase();
if ((normalizedKey === "parcelid" || normalizedKey === "parcelnumber") && hints.parcelId == null) {
if (typeof value === "string" || typeof value === "number") {
const candidate = collapseIdentifier(value);
if (isLikelyIdentifier(candidate)) {
hints.parcelId = candidate;
}
}
}
if ((normalizedKey === "apn" || normalizedKey === "apnnumber" || normalizedKey === "taxparcelid" || normalizedKey === "taxid") && hints.apn == null) {
if (typeof value === "string" || typeof value === "number") {
const candidate = collapseIdentifier(value);
if (isLikelyIdentifier(candidate)) {
hints.apn = candidate;
}
}
}
if (value && typeof value === "object") {
visitForIdentifierHints(value, hints);
}
}
}
export function extractZillowIdentifierHintsFromNextDataScript(scriptText) {
if (typeof scriptText !== "string" || !scriptText.trim()) {
return {};
}
let nextData;
try {
nextData = JSON.parse(scriptText);
} catch {
return {};
}
const hints = {};
visitForIdentifierHints(nextData, hints);
const cacheText = nextData?.props?.pageProps?.componentProps?.gdpClientCache;
if (typeof cacheText === "string" && cacheText.trim()) {
try {
visitForIdentifierHints(JSON.parse(cacheText), hints);
} catch {
// Ignore cache parse failures; base next-data parse already succeeded.
}
}
return hints;
}
export function extractZillowIdentifierHintsFromText(text) {
const source = typeof text === "string" ? text : "";
const hints = {};
const parcelMatch = source.match(/\b(?:parcel|parcel number|parcel #|tax parcel)(?:\s*(?:number|#|no\.?))?\s*[:#]?\s*([A-Z0-9-]{4,40})\b/i);
if (parcelMatch) {
hints.parcelId = collapseIdentifier(parcelMatch[1]);
}
const apnMatch = source.match(/\b(?:apn|apn #|apn no\.?|tax id)(?:\s*(?:number|#|no\.?))?\s*[:#]?\s*([A-Z0-9-]{4,40})\b/i);
if (apnMatch) {
hints.apn = collapseIdentifier(apnMatch[1]);
}
return hints;
}
const DEFAULT_MINIMUM_TRUSTED_STRUCTURED_PHOTO_COUNT = 12;
export function shouldUseStructuredZillowPhotos(candidates, options = {}) {