Merge MKDT_0004

This commit is contained in:
2026-03-17 14:20:52 -04:00
parent 5f77d55d45
commit 86baa9de07
3 changed files with 131 additions and 17 deletions

View File

@@ -1537,7 +1537,8 @@ namespace MarketData.Helper
symbol = symbol.ToUpper();
WebProxy webProxy = HttpNetRequest.GetProxy("GetCompanyProfileYahoo");
sb.Append("http://finance.yahoo.com/q/pr?s=").Append(symbol).Append("+Profile");
// sb.Append("http://finance.yahoo.com/q/pr?s=").Append(symbol).Append("+Profile");
sb.Append("https://finance.yahoo.com/quote/").Append(symbol).Append("/profile/");
strRequest = sb.ToString();
MDTrace.WriteLine(LogLevel.DEBUG,strRequest);
httpNetResponse = HttpNetRequest.GetRequestNoEncodingV1(strRequest);
@@ -1559,17 +1560,8 @@ namespace MarketData.Helper
if (null != strIndustry && strIndustry.Contains(Constants.CONST_QUESTION)) strIndustry = strIndustry.Replace(Constants.CONST_QUESTION, " - ");
if (null != strSector && strSector.Contains(Constants.CONST_QUESTION)) strSector = strSector.Replace(Constants.CONST_QUESTION, " - ");
// Locate Description
String strDescription = Sections.LocateItem(httpNetResponse.ResponseString, "Description", 4);
if(null == strDescription)
{
List<int> indices = Sections.LocateAllOccurrences(httpNetResponse.ResponseString, "Description");
if(indices.Count>0)
{
List<String> sections = Sections.GetSections(httpNetResponse.ResponseString);
strDescription = Sections.GetFirstNonEmptyItemInSection(sections, indices[0]+1);
}
}
// Yahoo changed this... again.
String strDescription = ExtractLongBusinessSummary(httpNetResponse.ResponseString);
if(null!=strDescription && strDescription.Equals("Description Information Not Available"))
{
@@ -1602,6 +1594,44 @@ namespace MarketData.Helper
}
}
/// <summary>
/// Retrieve the Company Description field in the Yahoo Company Profile Data
/// </summary>
/// <param name="html"></param>
/// <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;
// 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 jsonEnd = html.IndexOf("</script>", jsonStart);
if (jsonEnd < 0) return null;
string outerJson = html.Substring(jsonStart, jsonEnd - jsonStart);
// 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;
// parse inner JSON
JObject inner = Newtonsoft.Json.Linq.JObject.Parse(bodyJson);
return inner["quoteSummary"]?["result"]?[0]?["assetProfile"]?["longBusinessSummary"]?.ToString();
}
/// <summary>
/// Retrieve company profile information from MorningStar
/// </summary>
@@ -1622,7 +1652,8 @@ namespace MarketData.Helper
sb.Append(String.Format("https://www.morningstar.com/stocks/{0}/{1}/quote",exchange,symbol));
strRequest = sb.ToString();
MDTrace.WriteLine(LogLevel.DEBUG,strRequest);
httpNetResponse = HttpNetRequest.GetRequestNoEncodingV5A(strRequest, 15000, webProxy);
// httpNetResponse = HttpNetRequest.GetRequestNoEncodingV5A(strRequest, 15000, webProxy);
httpNetResponse = HttpNetRequest.GetRequestV6(strRequest, 15000, webProxy);
if(!httpNetResponse.Success)
{