Add Logic for EuroMillions DrawNumber
This commit is contained in:
56
lottery-co-uk-scraper/EuroMillions/DrawNumber.cs
Normal file
56
lottery-co-uk-scraper/EuroMillions/DrawNumber.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using HtmlAgilityPack;
|
||||
using lottery_co_uk_scraper.core.Models;
|
||||
using lottery_co_uk_scraper.Utilities;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace lottery_co_uk_scraper.EuroMillions
|
||||
{
|
||||
internal class DrawNumber
|
||||
{
|
||||
public static int ProcessDrawNumberFromMeta(HtmlDocument doc, EurosResult eurosResult)
|
||||
{
|
||||
var metaKeywords = doc.DocumentNode.Descendants("meta")
|
||||
.FirstOrDefault(x => x.GetAttributeValue("name", "") == "keywords");
|
||||
|
||||
if (metaKeywords != null)
|
||||
{
|
||||
var keywordsText = metaKeywords.GetAttributeValue("content", "");
|
||||
var drawNumberMatch = Regex.Match(keywordsText, @"euromillions draw (\d+)");
|
||||
|
||||
if (drawNumberMatch.Success)
|
||||
{
|
||||
if (int.TryParse(drawNumberMatch.Groups[1].Value, out int drawNumber))
|
||||
{
|
||||
Console.WriteLine("Draw Number: " + drawNumber);
|
||||
|
||||
AssignDrawNumberToModelProperty(drawNumber, eurosResult);
|
||||
return drawNumber;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Failed to parse draw number.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Draw Number not found.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Meta keywords not found.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static void AssignDrawNumberToModelProperty(int drawNumber, EurosResult eurosResult)
|
||||
{
|
||||
PropertyManager.SetProperty(nameof(eurosResult.DrawNumber), eurosResult, drawNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user