include cache update

This commit is contained in:
fox
2026-06-24 11:51:15 +01:00
parent 689276ea7d
commit a2a6c15808
64 changed files with 744 additions and 1104 deletions
@@ -1,5 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Net.Http.Headers;
using Solicitors.Core.Misc;
using Solicitors.Core.Models.Imports;
using Solicitors.HtmlParsing;
@@ -154,7 +153,7 @@ internal class SolicitorParser : ISolicitorParser
ParseSidebar(sidebarChildren, out phone, out email, out website, out ratings);
}
return new SolicitorData()
return new SolicitorData
{
Name = builder.Name,
UrlPath = builder.Path,
@@ -168,14 +167,14 @@ internal class SolicitorParser : ISolicitorParser
};
}
Location[] ParseOffices(IEnumerable<IHtmlNode> officeNodes)
private Location[] ParseOffices(IEnumerable<IHtmlNode> officeNodes)
=> officeNodes
.Select(ParseOffice)
.Where(x => x is not null)
.Cast<Location>()
.ToArray();
Location? ParseOffice(IHtmlNode officeNode)
private Location? ParseOffice(IHtmlNode officeNode)
{
if (!officeNode.TryGetChildren(out var officeChildren)
|| !officeNode.TryGetByTagName("address", out var addressNode)
@@ -183,7 +182,7 @@ internal class SolicitorParser : ISolicitorParser
return null;
Location? location = null;
string? address = "";
var address = "";
foreach (var line in addressLines)
{
if (line.TryGetText(out var lineText))
@@ -214,7 +213,7 @@ internal class SolicitorParser : ISolicitorParser
return location;
}
void ParseSidebar(
private void ParseSidebar(
IEnumerable<IHtmlNode> sidebarChildren,
out string? phone,
out string? email,
@@ -253,7 +252,7 @@ internal class SolicitorParser : ISolicitorParser
foreach (var child in childrenArray.Where(x => x.TryGetByClass("rev-box", out _, true)))
{
if (child.TryGetAttributeValue("title", out var ratingString)
&& TryParseRatingString(ratingString, out decimal rating, out decimal maxRating)
&& TryParseRatingString(ratingString, out var rating, out var maxRating)
&& child.TryGetByTagNameAndClass("img", "rev-logo", out var imgNode)
&& imgNode.TryGetAttributeValue("src", out var imgSrc)
&& TryParseRatingSrc(imgSrc, out var ratingProvider))
@@ -290,15 +289,15 @@ internal class SolicitorParser : ISolicitorParser
return decimal.TryParse(parts[0], out rating) && decimal.TryParse(parts[1], out maxRating);
}
bool TryParseRatingSrc(string imgSrc, out string provider)
private bool TryParseRatingSrc(string imgSrc, out string provider)
{
provider = "";
imgSrc = imgSrc.Trim('"');
var prefix = "/images/logo-";
const string prefix = "/images/logo-";
if (!imgSrc.StartsWith(prefix))
return false;
var providerAndExtension = imgSrc.Substring(prefix.Length);
var providerAndExtension = imgSrc[prefix.Length..];
provider = providerAndExtension.Split('.').First();
return true;
}
@@ -306,11 +305,11 @@ internal class SolicitorParser : ISolicitorParser
bool TryParseOwnRatingString(string ratingString, out decimal rating)
{
rating = 0;
var prefix = "Average review score : ";
const string prefix = "Average review score : ";
if (!ratingString.StartsWith(prefix))
return false;
var ratingPart = ratingString.Substring(prefix.Length);
var ratingPart = ratingString[prefix.Length..];
return decimal.TryParse(ratingPart, out rating);
}
}