2 * rhynodge - ScandinaviaAndTheWorldWatcher.java - Copyright © 2013 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.rhynodge.watchers;
20 import java.util.List;
22 import net.pterodactylus.rhynodge.Filter;
23 import net.pterodactylus.rhynodge.filters.ExtractUrlFilter;
24 import net.pterodactylus.rhynodge.filters.HtmlFilter;
25 import net.pterodactylus.rhynodge.filters.HttpQueryFilter;
26 import net.pterodactylus.rhynodge.filters.comics.ScandinaviaAndTheWorldComicFilter;
27 import net.pterodactylus.rhynodge.queries.HttpQuery;
28 import net.pterodactylus.rhynodge.triggers.NewComicTrigger;
30 import com.google.common.base.Optional;
31 import com.google.common.collect.ImmutableList;
32 import org.jsoup.nodes.Document;
33 import org.jsoup.select.Elements;
36 * {@link net.pterodactylus.rhynodge.Watcher} implementation that watches for new Scandinavia and the World comics.
38 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
40 public class ScandinaviaAndTheWorldWatcher extends DefaultWatcher {
42 public ScandinaviaAndTheWorldWatcher() {
43 super(new HttpQuery("http://satwcomic.com/"), createFilters(), new NewComicTrigger());
46 private static List<Filter> createFilters() {
47 ImmutableList.Builder<Filter> filters = ImmutableList.builder();
49 filters.add(new HtmlFilter());
50 filters.add(new ExtractUrlFilter() {
53 protected Optional<String> extractUrl(Document document) {
54 Elements linkTag = document.select("a.btn-success");
55 return linkTag.hasAttr("href") ? Optional.of(linkTag.attr("href")) : Optional.<String>absent();
58 filters.add(new HttpQueryFilter());
59 filters.add(new HtmlFilter());
60 filters.add(new ScandinaviaAndTheWorldComicFilter());
62 return filters.build();