Add purpose-aware property assessor intake
This commit is contained in:
66
skills/property-assessor/src/listing-discovery.ts
Normal file
66
skills/property-assessor/src/listing-discovery.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
|
||||
export interface ListingDiscoveryResult {
|
||||
attempts: string[];
|
||||
zillowUrl: string | null;
|
||||
harUrl: string | null;
|
||||
}
|
||||
|
||||
function parseJsonOutput(raw: string, context: string): any {
|
||||
const text = raw.trim();
|
||||
if (!text) {
|
||||
throw new Error(`${context} produced no JSON output.`);
|
||||
}
|
||||
return JSON.parse(text);
|
||||
}
|
||||
|
||||
async function runDiscoveryScript(
|
||||
scriptName: string,
|
||||
address: string
|
||||
): Promise<{ listingUrl: string | null; attempts: string[] }> {
|
||||
const scriptPath = `/Users/stefano/.openclaw/workspace/skills/web-automation/scripts/${scriptName}`;
|
||||
const { stdout } = await execFileAsync(process.execPath, [scriptPath, address], {
|
||||
timeout: 120000,
|
||||
maxBuffer: 2 * 1024 * 1024
|
||||
});
|
||||
const payload = parseJsonOutput(stdout, scriptName);
|
||||
return {
|
||||
listingUrl: typeof payload.listingUrl === "string" && payload.listingUrl.trim() ? payload.listingUrl.trim() : null,
|
||||
attempts: Array.isArray(payload.attempts) ? payload.attempts.map(String) : []
|
||||
};
|
||||
}
|
||||
|
||||
export async function discoverListingSources(address: string): Promise<ListingDiscoveryResult> {
|
||||
const attempts: string[] = [];
|
||||
let zillowUrl: string | null = null;
|
||||
let harUrl: string | null = null;
|
||||
|
||||
try {
|
||||
const result = await runDiscoveryScript("zillow-discover.js", address);
|
||||
zillowUrl = result.listingUrl;
|
||||
attempts.push(...result.attempts);
|
||||
} catch (error) {
|
||||
attempts.push(
|
||||
`Zillow discovery failed: ${error instanceof Error ? error.message : String(error)}`
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await runDiscoveryScript("har-discover.js", address);
|
||||
harUrl = result.listingUrl;
|
||||
attempts.push(...result.attempts);
|
||||
} catch (error) {
|
||||
attempts.push(
|
||||
`HAR discovery failed: ${error instanceof Error ? error.message : String(error)}`
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
attempts,
|
||||
zillowUrl,
|
||||
harUrl
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user