Add debug logging for OO_STATE keys and title tag fallback
- Log all top-level keys in __OO_STATE__ to diagnose why Restaurant key isn't being found - Extract business name from HTML title tag as fallback Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
5c49054e78
commit
e8dfd0ba7d
1 changed files with 18 additions and 0 deletions
|
|
@ -172,6 +172,21 @@
|
||||||
</cfloop>
|
</cfloop>
|
||||||
</cfif>
|
</cfif>
|
||||||
|
|
||||||
|
<!--- Try to extract business name from title tag --->
|
||||||
|
<cfset titleMatch = reMatchNoCase('<title>([^<]+)</title>', pageHtml)>
|
||||||
|
<cfif arrayLen(titleMatch)>
|
||||||
|
<cfset titleText = reReplaceNoCase(titleMatch[1], '.*<title>([^<]+)</title>.*', '\1')>
|
||||||
|
<cfset titleText = trim(titleText)>
|
||||||
|
<!--- Toast titles are usually "Restaurant Name | Online Ordering" --->
|
||||||
|
<cfif findNoCase("|", titleText)>
|
||||||
|
<cfset titleText = trim(listFirst(titleText, "|"))>
|
||||||
|
</cfif>
|
||||||
|
<cfif len(titleText) AND NOT structKeyExists(toastBusiness, "name")>
|
||||||
|
<cfset toastBusiness["name"] = titleText>
|
||||||
|
<cfset arrayAppend(response.steps, "Extracted business name from title: " & titleText)>
|
||||||
|
</cfif>
|
||||||
|
</cfif>
|
||||||
|
|
||||||
<!--- Also try to extract from __OO_STATE__ for images and business info --->
|
<!--- Also try to extract from __OO_STATE__ for images and business info --->
|
||||||
<cfif findNoCase("window.__OO_STATE__", pageHtml)>
|
<cfif findNoCase("window.__OO_STATE__", pageHtml)>
|
||||||
<cfset ooStateMatch = reMatchNoCase("window\.__OO_STATE__\s*=\s*(\{.*?\});\s*window\.", pageHtml)>
|
<cfset ooStateMatch = reMatchNoCase("window\.__OO_STATE__\s*=\s*(\{.*?\});\s*window\.", pageHtml)>
|
||||||
|
|
@ -180,6 +195,9 @@
|
||||||
<cfset ooStateJson = reReplace(ooStateJson, ";\s*window\.$", "")>
|
<cfset ooStateJson = reReplace(ooStateJson, ";\s*window\.$", "")>
|
||||||
<cftry>
|
<cftry>
|
||||||
<cfset ooState = deserializeJSON(ooStateJson)>
|
<cfset ooState = deserializeJSON(ooStateJson)>
|
||||||
|
<!--- Debug: log all top-level keys in OO_STATE --->
|
||||||
|
<cfset ooStateKeys = structKeyList(ooState)>
|
||||||
|
<cfset arrayAppend(response.steps, "OO_STATE keys: " & left(ooStateKeys, 500))>
|
||||||
<!--- Build name -> image URL map from OO_STATE --->
|
<!--- Build name -> image URL map from OO_STATE --->
|
||||||
<cfset imageMap = structNew()>
|
<cfset imageMap = structNew()>
|
||||||
<cfloop collection="#ooState#" item="key">
|
<cfloop collection="#ooState#" item="key">
|
||||||
|
|
|
||||||
Reference in a new issue