1 package be
.nikiroo
.gofetch
.support
;
3 import java
.io
.IOException
;
4 import java
.io
.InputStream
;
6 import java
.util
.ArrayList
;
9 import org
.jsoup
.helper
.DataUtil
;
10 import org
.jsoup
.nodes
.Document
;
11 import org
.jsoup
.nodes
.Element
;
12 import org
.jsoup
.nodes
.Node
;
13 import org
.jsoup
.select
.Elements
;
15 import be
.nikiroo
.gofetch
.data
.Comment
;
16 import be
.nikiroo
.gofetch
.data
.Story
;
17 import be
.nikiroo
.utils
.StringUtils
;
20 * Support <a href="https://www.toolinux.com/">https://www.toolinux.com/</a>.
24 public class TooLinux
extends BasicSupport
{
26 public String
getDescription() {
27 return "TooLinux: Actualité généraliste sur Linux et les logiciels libres";
31 public List
<Story
> list() throws IOException
{
32 List
<Story
> list
= new ArrayList
<Story
>();
34 URL url
= new URL("https://www.toolinux.com/");
35 InputStream in
= downloader
.open(url
);
36 Document doc
= DataUtil
.load(in
, "UTF-8", url
.toString());
37 Elements articles
= doc
.getElementsByClass("hentry");
38 for (Element article
: articles
) {
41 String extUrl
= ""; // nope
46 String author
= ""; // nope
47 String categ
= ""; // nope
49 Element urlElement
= article
.getElementsByTag("a").first();
50 if (urlElement
!= null) {
51 intUrl
= urlElement
.absUrl("href");
54 Element titleElement
= article
.getElementsByClass("entry-title")
56 if (titleElement
!= null) {
57 title
= StringUtils
.unhtml(titleElement
.text()).trim();
60 Element dateElement
= article
.getElementsByClass("published")
62 if (dateElement
!= null) {
63 date
= StringUtils
.unhtml(dateElement
.text()).trim();
64 id
= dateElement
.attr("title").trim();
69 id
= intUrl
.replace("/", "_");
72 Element bodyElement
= article
.getElementsByClass("introduction")
74 if (bodyElement
!= null) {
75 body
= StringUtils
.unhtml(bodyElement
.text()).trim();
78 list
.add(new Story(getType(), id
, title
, author
, date
, categ
,
79 details
, intUrl
, extUrl
, body
));
86 public void fetch(Story story
) throws IOException
{
87 String fullContent
= story
.getContent();
88 List
<Comment
> comments
= new ArrayList
<Comment
>();
89 story
.setComments(comments
);
91 URL url
= new URL(story
.getUrlInternal());
92 InputStream in
= downloader
.open(url
);
94 Document doc
= DataUtil
.load(in
, "UTF-8", url
.toString());
95 Element article
= doc
.getElementById("content");
96 if (article
!= null) {
97 for (String line
: toLines(article
,
98 new BasicElementProcessor() {
100 public boolean ignoreNode(Node node
) {
101 if ("notes".equals(node
.attr("class"))) {
107 fullContent
+= line
+ "\n";
110 // Content is too tight with a single break per line:
111 fullContent
= fullContent
.replace("\n", "\n\n") //
112 .replace("\n\n\n\n", "\n\n") //
113 .replace("\n\n\n\n", "\n\n") //
117 story
.setFullContent(fullContent
);