From 0bf557e80c2a0bedcfe5f2c82fe8cd82bf93d2cb Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 24 Jan 2015 02:34:29 +0100 Subject: [PATCH] Add business cat comic watcher. --- .../filters/comics/BusinessCatComicFilter.java | 35 ++ .../rhynodge/watchers/BusinessCatWatcher.java | 22 + .../filters/comics/BusinessCatComicFilterTest.java | 46 ++ .../rhynodge/filters/comics/business-cat.html | 477 +++++++++++++++++++++ 4 files changed, 580 insertions(+) create mode 100644 src/main/java/net/pterodactylus/rhynodge/filters/comics/BusinessCatComicFilter.java create mode 100644 src/main/java/net/pterodactylus/rhynodge/watchers/BusinessCatWatcher.java create mode 100644 src/test/java/net/pterodactylus/rhynodge/filters/comics/BusinessCatComicFilterTest.java create mode 100644 src/test/resources/net/pterodactylus/rhynodge/filters/comics/business-cat.html diff --git a/src/main/java/net/pterodactylus/rhynodge/filters/comics/BusinessCatComicFilter.java b/src/main/java/net/pterodactylus/rhynodge/filters/comics/BusinessCatComicFilter.java new file mode 100644 index 0000000..7b75008 --- /dev/null +++ b/src/main/java/net/pterodactylus/rhynodge/filters/comics/BusinessCatComicFilter.java @@ -0,0 +1,35 @@ +package net.pterodactylus.rhynodge.filters.comics; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import net.pterodactylus.rhynodge.filters.ComicSiteFilter; + +import com.google.common.base.Optional; +import org.jsoup.nodes.Document; + +/** + * {@link ComicSiteFilter} implementation that can parse Business Cat comics. + * + * @author David ‘Bombe’ Roden + */ +public class BusinessCatComicFilter extends ComicSiteFilter { + + @Override + protected Optional extractTitle(Document document) { + String title = document.select("#comic img").attr("title"); + return title.isEmpty() ? Optional.absent() : Optional.of(title); + } + + @Override + protected List extractImageUrls(Document document) { + return Arrays.asList(document.select("#comic img").attr("src")); + } + + @Override + protected List extractImageComments(Document document) { + return Collections.emptyList(); + } + +} diff --git a/src/main/java/net/pterodactylus/rhynodge/watchers/BusinessCatWatcher.java b/src/main/java/net/pterodactylus/rhynodge/watchers/BusinessCatWatcher.java new file mode 100644 index 0000000..0ffa41a --- /dev/null +++ b/src/main/java/net/pterodactylus/rhynodge/watchers/BusinessCatWatcher.java @@ -0,0 +1,22 @@ +package net.pterodactylus.rhynodge.watchers; + +import java.util.Arrays; + +import net.pterodactylus.rhynodge.Watcher; +import net.pterodactylus.rhynodge.filters.HtmlFilter; +import net.pterodactylus.rhynodge.filters.comics.BusinessCatComicFilter; +import net.pterodactylus.rhynodge.queries.HttpQuery; +import net.pterodactylus.rhynodge.triggers.NewComicTrigger; + +/** + * {@link Watcher} implementation that watches for new Business Cat comics. + * + * @author David ‘Bombe’ Roden + */ +public class BusinessCatWatcher extends DefaultWatcher { + + public BusinessCatWatcher() { + super(new HttpQuery("http://www.businesscat.happyjar.com/"), Arrays.asList(new HtmlFilter(), new BusinessCatComicFilter()), new NewComicTrigger()); + } + +} diff --git a/src/test/java/net/pterodactylus/rhynodge/filters/comics/BusinessCatComicFilterTest.java b/src/test/java/net/pterodactylus/rhynodge/filters/comics/BusinessCatComicFilterTest.java new file mode 100644 index 0000000..5b9e916 --- /dev/null +++ b/src/test/java/net/pterodactylus/rhynodge/filters/comics/BusinessCatComicFilterTest.java @@ -0,0 +1,46 @@ +package net.pterodactylus.rhynodge.filters.comics; + +import java.io.IOException; +import java.io.InputStream; + +import com.google.common.base.Optional; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.junit.Test; + +/** + * Unit test for {@link BusinessCatComicFilter}. + */ +public class BusinessCatComicFilterTest { + + private final BusinessCatComicFilter filter = new BusinessCatComicFilter(); + private final Document document; + + public BusinessCatComicFilterTest() throws IOException { + document = loadDocument("business-cat.html", "http://www.businesscat.happyjar.com//"); + } + + private Document loadDocument(String resourceName, String baseUri) throws IOException { + InputStream inputStream = getClass().getResourceAsStream(resourceName); + Document document = Jsoup.parse(inputStream, "UTF-8", baseUri); + return document; + } + + @Test + public void imageTitleCanBeExtracted() { + MatcherAssert.assertThat(filter.extractTitle(document), Matchers.is(Optional.of("Running Late"))); + } + + @Test + public void imageUrlsCanBeExtracted() { + MatcherAssert.assertThat(filter.extractImageUrls(document), Matchers.contains("http://www.businesscat.happyjar.com/wp-content/uploads/2015/01/2015-01-23-Running-Late.png")); + } + + @Test + public void imageCommentsCanBeExtracted() { + MatcherAssert.assertThat(filter.extractImageComments(document), Matchers.empty()); + } + +} diff --git a/src/test/resources/net/pterodactylus/rhynodge/filters/comics/business-cat.html b/src/test/resources/net/pterodactylus/rhynodge/filters/comics/business-cat.html new file mode 100644 index 0000000..8e45833 --- /dev/null +++ b/src/test/resources/net/pterodactylus/rhynodge/filters/comics/business-cat.html @@ -0,0 +1,477 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + The Adventures of Business Cat | You've earned it. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+
+
+
+ + + + +
+ +
+ +
+ + +
+ +  
The Adventures of Business Cat is proudly supported by these good folks.
+   
+ + +
   +   
+ + + + +
+   +
+ +
+
+ + +
Running Late +
+ +

It’s a serious problem.

+
+ +
comments (4) + +
+ +
+ +
+ + + +
Australia +
+ +

Hey guys, I’m going to be heading to Australia for a couple of weeks as of tomorrow and unfortunately that means no more comics between now and when I get back. I would have liked to have finished some comics to tide me over while I’m gone, but between my computer being dead the last two weeks and last minute preparations for my trip, that didn’t turn out to be possible.

+

As with last month, I would encourage my Patreon users to decline payment for the month of December as it looks like it’s going to be a bit haphazard again. Here’s to getting back on track with stable updates in the New Year (but probably a bit before then).

+
+ +
comments (1) + +
+ +
+ + + +
Involuntary Hiatus +
+ +

I sometimes forget that not everyone who reads this comic also follows me on Facebook or Twitter. So for those of you who have been left in the dark on this, here’s where we’re at right now.

+

Last Monday my computer up and died on me. It was functioning perfectly the night before and the next morning I go to turn it on and the LCD screen is a garbled mess. A new screen had to be ordered in for me and on Friday evening it was replaced. The screen looks perfect and I was ready and willing to get started on some new comics for Monday when it soon became apparent that the LCD screen was not the full extent of the problem.

+

Long story short, my computer is still entirely unusable and at this rate it looks like I may not even be able to get it seen by the appropriate parties until Nov 20. I’ve no idea how long it may take to resolve the problem after that. Until that day, however, I have no way of creating and uploading new comics. And if you think you’re bummed about that, I can tell you that I’m about ten times more bummed than you are.

+

From bad to worse, I will be in Australia for a few weeks from Dec 5. If I can’t get it fixed soon I may not have time to sort out some comics in advance of my trip. These are dark times. But rest assured, I will be back up and running eventually. Watch my social media for any updates.

+

Finally, here are the long boring details of my current problem for anyone who may be able to help. If so, shoot me an e-mail:

+

Fan is extremely loud upon booting up and the computer slows to a crawl making it almost impossible to do anything. Activity Monitor shows that CPU usage is around 80-90% even when zero apps are open. Process called ‘kernel_task’ is reading at 600-800% CPU usage. Multiple SMC and PRAM resets have yielded no results. Running 27″ iMac w/ SSD and upgraded to Yosemite about two-three weeks ago.

+
+ +
comments (6) + +
+ +
+ + + +
New Patreon +
+ +

Hey guys,

+

My content is and always will remain free, but if you’d like to help support what I do (and get some extra content and behind the scenes updates in return), then please consider taking a look at my new Patreon page.

+

+
+ +
comments (0) + +
+ +
+ + + + +
+ +
+ + + +
+ + +
+ +
+ + + + + + + + + + + + + + + -- 2.7.4