Skip to content

Commit

Permalink
Modify giveaway XPath and parse logic due to GOG giveaway banner change.
Browse files Browse the repository at this point in the history
  • Loading branch information
azhuge233 committed Jun 21, 2024
1 parent a88752b commit 3c0c673
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 3 additions & 1 deletion GOGGiveawayNotifier/Model/String/ParseStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ public static class ParseStrings {
public static readonly string removeSpecialCharsRegex = @"[^0-9a-zA-Z]+";

#region Xpath
public static readonly string titleLableXpath = ".//a[@giveaway-banner]";
public static readonly string giveawayDivXPath = ".//div[contains(@id, \'giveaway\')]";
public static readonly string giveawayALinkXPath = ".//a[contains(@class, \'giveaway__overlay-link\')]";
//public static readonly string titleLableXpath = ".//a[@giveaway-banner]";
public static readonly string productTileXPath = ".//div[contains(@class, \'grid\')]//product-tile";
public static readonly string productLinkXPath = ".//a[contains(@class, \'product-tile\')]";
public static readonly string productTitleSpanXPath = ".//a[contains(@class, 'product-tile')]//div[contains(@class, \'product-tile__info\')]//div[contains(@class, \'product-tile__title\')]//product-title//span";
Expand Down
14 changes: 11 additions & 3 deletions GOGGiveawayNotifier/Module/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,26 @@ public Tuple<List<GiveawayRecord>, List<GiveawayRecord>> ParseGiveaway(HtmlDocum
try {
_logger.LogDebug(debugParseGiveaway);

var titleHref = htmlDoc.DocumentNode.SelectSingleNode(ParseStrings.titleLableXpath);
var giveawayDiv = htmlDoc.DocumentNode.SelectSingleNode(ParseStrings.giveawayDivXPath);
var resultList = new List<GiveawayRecord>();
var notifyList = new List<GiveawayRecord>();

if (titleHref == null) {
if (giveawayDiv == null) {
_logger.LogDebug("No giveaway detected");
_logger.LogDebug($"Done: {debugParseGiveaway}");
return new Tuple<List<GiveawayRecord>, List<GiveawayRecord>>(resultList, notifyList);
}

var giveawayALink = giveawayDiv.SelectSingleNode(ParseStrings.giveawayALinkXPath);

if (giveawayALink == null) {
_logger.LogDebug("Get giveaway link failed");
_logger.LogDebug($"Done: {debugParseGiveaway}");
return new Tuple<List<GiveawayRecord>, List<GiveawayRecord>>(resultList, notifyList);
}

var newGiveaway = new GiveawayRecord {
Name = titleHref.Attributes["ng-href"].Value.Split("/game/")[^1].Replace("_", " "),
Name = giveawayALink.Attributes["href"].Value.Split("/game/").Last().Replace("_", " "),
Url = ParseStrings.GiveawayUrl
};
var textInfo = new CultureInfo("en-US", false).TextInfo;
Expand Down

0 comments on commit 3c0c673

Please sign in to comment.