🐛 Fix broken change detection
[rhynodge.git] / src / main / java / net / pterodactylus / rhynodge / watchers / ScandinaviaAndTheWorldWatcher.java
1 /*
2  * rhynodge - ScandinaviaAndTheWorldWatcher.java - Copyright © 2013 David Roden
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 package net.pterodactylus.rhynodge.watchers;
19
20 import java.util.List;
21
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.mergers.ComicMerger;
28 import net.pterodactylus.rhynodge.queries.HttpQuery;
29
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;
34
35 /**
36  * {@link net.pterodactylus.rhynodge.Watcher} implementation that watches for new Scandinavia and the World comics.
37  *
38  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
39  */
40 public class ScandinaviaAndTheWorldWatcher extends DefaultWatcher {
41
42         public ScandinaviaAndTheWorldWatcher() {
43                 super(new HttpQuery("http://satwcomic.com/"), createFilters(), new ComicMerger());
44         }
45
46         private static List<Filter> createFilters() {
47                 ImmutableList.Builder<Filter> filters = ImmutableList.builder();
48
49                 filters.add(new HtmlFilter());
50                 filters.add(new ExtractUrlFilter() {
51
52                         @Override
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();
56                         }
57                 });
58                 filters.add(new HttpQueryFilter());
59                 filters.add(new HtmlFilter());
60                 filters.add(new ScandinaviaAndTheWorldComicFilter());
61
62                 return filters.build();
63         }
64
65 }