Compare commits

...

4 Commits

Author SHA1 Message Date
Ross Healy
9106dd85d7 remove url 2024-02-07 19:17:40 +00:00
Ross Healy
734bcd0725 Reordered methods called to decide which information is pulled. 2024-02-07 19:17:19 +00:00
Ross Healy
f40ecfff58 Ugly AF but now processes rolldown values. 2024-02-07 19:16:52 +00:00
Ross Healy
bc35ff7c2c Additional properties for rolldown prizes. 2024-02-06 21:52:03 +00:00
4 changed files with 211 additions and 6 deletions

View File

@@ -36,18 +36,24 @@
public decimal Matched2PrizeFund { get; set; }
public decimal Matched2RolldownPrize { get; set; }
public decimal TotalMatched3 { get; set; }
public decimal Matched3Prize { get; set; }
public decimal Matched3PrizeFund { get; set; }
public decimal Matched3RolldownPrize { get; set; }
public decimal TotalMatched4 { get; set; }
public decimal Matched4Prize { get; set; }
public decimal Matched4PrizeFund { get; set; }
public decimal Matched4RolldownPrize { get; set; }
public decimal TotalMatched5 { get; set; }
public decimal Matched5Prize { get; set; }
@@ -56,16 +62,22 @@
public decimal TotalMatched5PlusBonus { get; set; }
public decimal Matched5RolldownPrize { get; set; }
public decimal Matched5PlusBonusPrize { get; set; }
public decimal Matched5PlusBonusPrizeFund { get; set; }
public decimal Matched5PlusBonusRolldownPrize { get; set; }
public decimal TotalMatched6 { get; set; }
public decimal Matched6Prize { get; set; }
public decimal Matched6PrizeFund { get; set; }
public decimal Matched6RolldownPrize { get; set; }
public int TotalWinners { get; set; }
public decimal TotalPrizeFund {get; set;}

View File

@@ -3,6 +3,7 @@ using lottery_co_uk_scraper.core.Models;
using static lottery_co_uk_scraper.NationalLottery.Lotto;
using System.Globalization;
using lottery_co_uk_scraper.Utilities;
using System.Text.RegularExpressions;
namespace lottery_co_uk_scraper.NationalLottery
{
@@ -17,14 +18,21 @@ namespace lottery_co_uk_scraper.NationalLottery
var winnersNode = GetNodeByDataTitle(sectionRow, LotteryTableRow.Winners);
var prizePerWinnerNode = GetNodeByDataTitle(sectionRow, LotteryTableRow.PrizePerWinner);
var prizeFundNode = GetNodeByDataTitle(sectionRow, LotteryTableRow.PrizeFundAmount);
var rolldown = lottoResult.Rolldown;
if (winnersNode != null && prizePerWinnerNode != null && prizeFundNode != null)
{
ProcessWinners(sectionTitle, winnersNode, lottoResult);
ProcessWinnerPrizeAmount(sectionTitle, prizePerWinnerNode, lottoResult);
ProcessPrizeFundAmount(sectionTitle, prizeFundNode, lottoResult);
if (rolldown == false)
{
ProcessWinnerPrizeAmount(sectionTitle, prizePerWinnerNode, lottoResult);
}
else
{
ProcessRolldownWinnerPrizeAmount(sectionTitle, prizePerWinnerNode, lottoResult);
}
}
else
{
@@ -36,7 +44,6 @@ namespace lottery_co_uk_scraper.NationalLottery
Console.WriteLine($"Section title '{sectionTitle}' not found in the table.");
}
}
private static HtmlNode GetSectionRowByTitle(HtmlNode table, string sectionTitle)
{
return table.Descendants("tr")
@@ -195,6 +202,137 @@ namespace lottery_co_uk_scraper.NationalLottery
}
}
public static void AssignValueToModelProperty2(string sectionTitle, string propertyName, string columnTitle, decimal value, decimal rolloverPrizePerWinner, LottoResult lottoResult)
{
switch (sectionTitle)
{
case LotteryTableRow.Match2:
if (columnTitle == LotteryTableRow.Winners)
{
PropertyManager.SetProperty(nameof(lottoResult.TotalMatched2), lottoResult, value);
}
if (columnTitle == LotteryTableRow.PrizePerWinner)
{
PropertyManager.SetProperty(nameof(lottoResult.Matched2RolldownPrize), lottoResult, value);
}
if (columnTitle == LotteryTableRow.PrizeFundAmount)
{
PropertyManager.SetProperty(nameof(lottoResult.Matched2PrizeFund), lottoResult, rolloverPrizePerWinner);
}
break;
case LotteryTableRow.Match3:
if (columnTitle == LotteryTableRow.Winners)
{
PropertyManager.SetProperty(nameof(lottoResult.TotalMatched3), lottoResult, value);
}
if (columnTitle == LotteryTableRow.PrizePerWinner)
{
PropertyManager.SetProperty(nameof(lottoResult.Matched3Prize), lottoResult, value);
PropertyManager.SetProperty(nameof(lottoResult.Matched3RolldownPrize), lottoResult, rolloverPrizePerWinner);
}
if (columnTitle == LotteryTableRow.PrizeFundAmount)
{
PropertyManager.SetProperty(nameof(lottoResult.Matched3PrizeFund), lottoResult, value);
}
break;
case LotteryTableRow.Match4:
if (columnTitle == LotteryTableRow.Winners)
{
PropertyManager.SetProperty(nameof(lottoResult.TotalMatched4), lottoResult, value);
}
if (columnTitle == LotteryTableRow.PrizePerWinner)
{
PropertyManager.SetProperty(nameof(lottoResult.Matched4Prize), lottoResult, value);
PropertyManager.SetProperty(nameof(lottoResult.Matched4RolldownPrize), lottoResult, rolloverPrizePerWinner);
}
if (columnTitle == LotteryTableRow.PrizeFundAmount)
{
PropertyManager.SetProperty(nameof(lottoResult.Matched4PrizeFund), lottoResult, value);
}
break;
case LotteryTableRow.Match5:
if (columnTitle == LotteryTableRow.Winners)
{
PropertyManager.SetProperty(nameof(lottoResult.TotalMatched5), lottoResult, value);
}
if (columnTitle == LotteryTableRow.PrizePerWinner)
{
PropertyManager.SetProperty(nameof(lottoResult.Matched5Prize), lottoResult, value);
PropertyManager.SetProperty(nameof(lottoResult.Matched5RolldownPrize), lottoResult, rolloverPrizePerWinner);
}
if (columnTitle == LotteryTableRow.PrizeFundAmount)
{
PropertyManager.SetProperty(nameof(lottoResult.Matched5PrizeFund), lottoResult, value);
}
break;
case LotteryTableRow.Match5Bonus:
if (columnTitle == LotteryTableRow.Winners)
{
PropertyManager.SetProperty(nameof(lottoResult.TotalMatched5PlusBonus), lottoResult, value);
}
if (columnTitle == LotteryTableRow.PrizePerWinner)
{
PropertyManager.SetProperty(nameof(lottoResult.Matched5PlusBonusPrize), lottoResult, value);
PropertyManager.SetProperty(nameof(lottoResult.Matched5PlusBonusRolldownPrize), lottoResult, rolloverPrizePerWinner);
}
if (columnTitle == LotteryTableRow.PrizeFundAmount)
{
PropertyManager.SetProperty(nameof(lottoResult.Matched5PlusBonusPrizeFund), lottoResult, value);
}
break;
case LotteryTableRow.Match6:
if (columnTitle == LotteryTableRow.Winners)
{
PropertyManager.SetProperty(nameof(lottoResult.TotalMatched6), lottoResult, value);
}
if (columnTitle == LotteryTableRow.PrizePerWinner)
{
PropertyManager.SetProperty(nameof(lottoResult.Matched6Prize), lottoResult, value);
}
if (columnTitle == LotteryTableRow.PrizeFundAmount)
{
PropertyManager.SetProperty(nameof(lottoResult.Matched6PrizeFund), lottoResult, value);
}
break;
case LotteryTableRow.Total:
if (columnTitle == LotteryTableRow.Winners)
{
PropertyManager.SetProperty(nameof(lottoResult.TotalWinners), lottoResult, value);
}
if (columnTitle == LotteryTableRow.PrizeFundAmount)
{
PropertyManager.SetProperty(nameof(lottoResult.TotalPrizeFund), lottoResult, value);
}
break;
}
}
public static void ProcessWinners(string sectionTitle, HtmlNode winnersNode, LottoResult lottoResult)
{
if (int.TryParse(winnersNode.InnerText.Trim().Replace(",", ""), NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out int winners))
@@ -251,6 +389,60 @@ namespace lottery_co_uk_scraper.NationalLottery
AssignValueToModelProperty(sectionTitle, LotteryTableRow.Match2, columnTitle, prizePerWinner, lottoResult);
}
public static void ProcessRolldownWinnerPrizeAmount(string sectionTitle, HtmlNode prizePerWinnerNode, LottoResult lottoResult)
{
decimal regularPrizePerWinner = 0;
decimal rolldownPrizePerWinner = 0;
string prizeText = prizePerWinnerNode.InnerHtml.Trim().Replace(",", "");
var htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml(prizeText);
var textNodes = htmlDoc.DocumentNode.DescendantsAndSelf().Where(n => n.NodeType == HtmlNodeType.Text);
var numericValues = textNodes.SelectMany(n => Regex.Matches(n.InnerHtml, @"(\d+)").Cast<Match>())
.Select(match => decimal.Parse(match.Groups[1].Value))
.ToList();
if (numericValues.Count >= 1)
{
regularPrizePerWinner = numericValues[0];
// Assuming you also need to handle the regular prize per winner
Console.WriteLine($"Regular Prize per winner ({sectionTitle}): {regularPrizePerWinner}");
if (numericValues.Count >= 2)
{
rolldownPrizePerWinner = numericValues[1];
Console.WriteLine($"Rolldown Prize per winner ({sectionTitle}): {rolldownPrizePerWinner}");
}
}
else if (prizeText == "Free Ticket")
{
regularPrizePerWinner = 99999999999M;
}
else
{
Console.WriteLine($"Failed to parse prize per winner ({sectionTitle}).");
return;
}
string columnTitle = prizePerWinnerNode.Attributes["data-title"].Value;
// Now you can use regularPrizePerWinner and rolldownPrizePerWinner as needed
Console.WriteLine($"Prize per winner ({sectionTitle}): {regularPrizePerWinner}");
Console.WriteLine($"Rolldown Prize per winner ({sectionTitle}): {rolldownPrizePerWinner}");
ParseWinnerRolloverPrizeAmount(sectionTitle, columnTitle, regularPrizePerWinner, rolldownPrizePerWinner, lottoResult);
}
public static void ParseWinnerRolloverPrizeAmount(string sectionTitle, string columnTitle, decimal value, decimal rolldownPrizePerWinne, LottoResult lottoResult)
{
AssignValueToModelProperty2(sectionTitle, LotteryTableRow.Match2, columnTitle, value, rolldownPrizePerWinne, lottoResult);
}
public static void ProcessPrizeFundAmount(string sectionTitle, HtmlNode prizeFundNode, LottoResult lottoResult)
{
string prizeFundText = prizeFundNode.InnerText.Trim().Replace("&pound;", "").Replace(",", "");

View File

@@ -20,11 +20,12 @@ namespace lottery_co_uk_scraper.NationalLottery
DrawBalls.ProcessBallSetUsed(doc, lottoResult);
DrawDate.ProcessDrawDateFromMeta(doc, lottoResult);
DrawNumber.ProcessDrawNumberFromMeta(doc, lottoResult);
DrawStatus.ProcessRollover(doc, lottoResult);
DrawStatus.ProcessRolldown(doc, lottoResult);
DrawBalls.ProcessMainBalls(doc, lottoResult);
DrawBalls.ProcessBonusBalls(doc, lottoResult);
DrawMachine.ProcessMachineUsed(doc, lottoResult);
DrawWinnerInformation.ProcessWinnersTable(doc, lottoResult);
DrawStatus.ProcessRolldown(doc, lottoResult);
DrawStatus.ProcessRollover(doc, lottoResult);
CommitToDatabase.SaveModelToDatabase(lottoResult);

View File

@@ -7,7 +7,7 @@ namespace lottery_co_uk_scraper
static async Task Main()
{
using HttpClient client = new();
string url = "https://www.lottery.co.uk/lotto/results-12-08-2023";
string url = "";
await Lotto.GetLottoNumbers(url, client);
}