Daily and code cleanup for headlines and ExtractLongBusinessSummary
Some checks failed
Build .NET Project / build (push) Has been cancelled

This commit is contained in:
2026-03-23 21:21:00 -04:00
parent 88d1504d26
commit 3bf89b97e8
4 changed files with 79 additions and 131 deletions

View File

@@ -1601,39 +1601,46 @@ namespace MarketData.Helper
/// <returns></returns>
public static string ExtractLongBusinessSummary(string html)
{
if(string.IsNullOrEmpty(html))return null;
// locate the script containing the assetProfile API response
int start = html.IndexOf("modules=assetProfile");
if (start < 0) return null;
try
{
if(string.IsNullOrEmpty(html))return null;
// locate the script containing the assetProfile API response
int start = html.IndexOf("modules=assetProfile");
if (start < 0) return null;
// move back to start of script tag
start = html.LastIndexOf("<script", start);
if (start < 0) return null;
// move back to start of script tag
start = html.LastIndexOf("<script", start);
if (start < 0) return null;
int jsonStart = html.IndexOf(">", start);
if (jsonStart < 0) return null;
jsonStart++;
int jsonStart = html.IndexOf(">", start);
if (jsonStart < 0) return null;
jsonStart++;
int jsonEnd = html.IndexOf("</script>", jsonStart);
if (jsonEnd < 0) return null;
int jsonEnd = html.IndexOf("</script>", jsonStart);
if (jsonEnd < 0) return null;
string outerJson = html.Substring(jsonStart, jsonEnd - jsonStart);
string outerJson = html.Substring(jsonStart, jsonEnd - jsonStart);
// parse outer JSON
JObject outer = Newtonsoft.Json.Linq.JObject.Parse(outerJson);
// parse outer JSON
JObject outer = Newtonsoft.Json.Linq.JObject.Parse(outerJson);
// body is escaped JSON
string bodyJson = outer["body"]?.ToString();
if (bodyJson == null) return null;
// body is escaped JSON
string bodyJson = outer["body"]?.ToString();
if (bodyJson == null) return null;
// parse inner JSON
JObject inner = Newtonsoft.Json.Linq.JObject.Parse(bodyJson);
JToken resultToken = inner["quoteSummary"]?["result"]; // Ensure result is an array with at least one element
if (resultToken is not JArray resultArray || resultArray.Count == 0)
// parse inner JSON
JObject inner = Newtonsoft.Json.Linq.JObject.Parse(bodyJson);
JToken resultToken = inner["quoteSummary"]?["result"]; // Ensure result is an array with at least one element
if (resultToken is not JArray resultArray || resultArray.Count == 0)
{
return null;
}
return resultArray[0]?["assetProfile"]?["longBusinessSummary"]?.ToString();
}
catch(Exception)
{
return null;
}
return resultArray[0]?["assetProfile"]?["longBusinessSummary"]?.ToString();
}
/// <summary>