Compare commits

...

4 Commits

Author SHA1 Message Date
03aab077d6 Add itemgroups. 2024-02-13 14:22:12 +00:00
298cfa53d9 Data model for game information 2024-02-13 14:20:38 +00:00
2e296f6d96 Generate the regular expression implementation at compile-time. 2024-02-13 14:12:10 +00:00
ae3e70313c Reoved potential null 2024-02-13 14:09:52 +00:00
4 changed files with 33 additions and 5 deletions

View File

@@ -0,0 +1,17 @@
namespace lottery_co_uk_scraper.core.Models
{
internal class GameInformation
{
public int Id { get; set; }
public string GameName { get; set; }
public DayOfWeek DrawDay { get; set; }
public TimeOnly DrawClosing { get; set; }
public TimeOnly DrawOpening { get; set; }
public TimeOnly DrawTime { get; set; }
}
}

View File

@@ -5,8 +5,11 @@ using System.Text.RegularExpressions;
namespace lottery_co_uk_scraper.EuroMillions
{
internal class DrawNumber
internal partial class DrawNumber
{
[GeneratedRegex(@"euromillions draw (\d+)")]
private static partial Regex MyRegex();
public static int ProcessDrawNumberFromMeta(HtmlDocument doc, EurosResult eurosResult)
{
var metaKeywords = doc.DocumentNode.Descendants("meta")
@@ -15,7 +18,7 @@ namespace lottery_co_uk_scraper.EuroMillions
if (metaKeywords != null)
{
var keywordsText = metaKeywords.GetAttributeValue("content", "");
var drawNumberMatch = Regex.Match(keywordsText, @"euromillions draw (\d+)");
var drawNumberMatch = MyRegex().Match(keywordsText);
if (drawNumberMatch.Success)
{

View File

@@ -194,15 +194,16 @@ namespace lottery_co_uk_scraper.NationalLottery
try
{
var bonusBallNode = ballsDrawn.Descendants("span")
.FirstOrDefault(x => x.HasClass(ballClass));
.FirstOrDefault(x => x.HasClass(ballClass));
if (bonusBallNode != null && int.TryParse(bonusBallNode.InnerText, out int bonusBall))
{
return bonusBall;
}
_logger.LogError("Failed to parse {className} value: {x.InnerText}", ballClass, x.InnerText);
throw new Exception($"Failed to parse {ballClass} value: {x.InnerText}");
_logger.LogError("Failed to parse {className}", ballClass);
throw new Exception($"Failed to parse {ballClass}");
}
catch
{

View File

@@ -21,4 +21,11 @@
<ProjectReference Include="..\lottery-co-uk-scraper.data\lottery-co-uk-scraper.data.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="EuroMillions\" />
<Folder Include="NationalLottery\" />
<Folder Include="SetForLife\" />
<Folder Include="Thunderball\" />
</ItemGroup>
</Project>