Skip to content

Commit

Permalink
Merge pull request #93 from goodtrailer/fix-falseknees-2025.111.0
Browse files Browse the repository at this point in the history
FalseKnees: Fix regex patterns
  • Loading branch information
goodtrailer authored Jan 11, 2025
2 parents 0e849cc + 71aa2c0 commit 07f79fa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 7 additions & 3 deletions DailyDesktop.Providers.FalseKnees/FalseKneesProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class FalseKneesProvider : IProvider
private const string AUTHOR = "Joshua Barkman";
private const string AUTHOR_URI = "https://falseknees.com/about.html";
private const string IMAGE_RELATIVE_URI_PATTERN = "imgs/[0-9]*?\\.[a-zA-Z]+";
private const string TITLE_RELATIVE_URI_PATTERN = "(?<=URL=)[0-9]+\\.[a-zA-Z]+";
private const string TITLE_RELATIVE_URI_PATTERN = "(?<=URL=).*?(?=\")";
private const string DESCRIPTION_PATTERN = "(?<=<img.*title=\").*?(?=\")";
private const string TITLE_PATTERN = "(?<=<p class=\"div-overflow\">.*?- ).*?(?=</p>)";

Expand All @@ -32,9 +32,13 @@ public async Task ConfigureWallpaperAsync(HttpClient client, IPublicWallpaperCon

string pageHtml = await client.GetStringAsync(SourceUri, cancellationToken);

string imageUri = SourceUri + "/comics/" + Regex.Match(pageHtml, IMAGE_RELATIVE_URI_PATTERN).Value;
string titleUri = SourceUri + "/" + Regex.Match(pageHtml, TITLE_RELATIVE_URI_PATTERN).Value;
string description = Regex.Match(pageHtml, DESCRIPTION_PATTERN).Value;

// Scrape info from image (title) page

string titleHtml = await client.GetStringAsync(titleUri, cancellationToken);
string imageUri = SourceUri + "/comics/" + Regex.Match(titleHtml, IMAGE_RELATIVE_URI_PATTERN).Value;
string description = Regex.Match(titleHtml, DESCRIPTION_PATTERN).Value;

// Scrape title from archive page

Expand Down
2 changes: 0 additions & 2 deletions DailyDesktop.Tests/TestProviders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,10 @@ public async Task TestFalseKnees()
var wallpaperConfig = new WallpaperConfiguration();
await new FalseKneesProvider().ConfigureWallpaperAsync(wallpaperConfig, AsyncUtils.LongCancel());

TestContext.WriteLine("Description: " + wallpaperConfig.Description);
TestContext.WriteLine("Image URI: " + wallpaperConfig.ImageUri);
TestContext.WriteLine("Title: " + wallpaperConfig.Title);
TestContext.WriteLine("Title URI: " + wallpaperConfig.TitleUri);

Assert.IsFalse(string.IsNullOrWhiteSpace(wallpaperConfig.Description), "Null/whitespace description.");
Assert.IsFalse(string.IsNullOrWhiteSpace(wallpaperConfig.ImageUri), "Null/whitespace image URI!");
Assert.IsFalse(string.IsNullOrWhiteSpace(wallpaperConfig.Title), "Null/whitespace title.");
Assert.IsFalse(string.IsNullOrWhiteSpace(wallpaperConfig.TitleUri), "Null/whitespace title URI.");
Expand Down

0 comments on commit 07f79fa

Please sign in to comment.