Small fixes in different places
[gofetch.git] / src / be / nikiroo / gofetch / support / Pipedot.java
index 89932f7636c170abc3b34b7c71542880b255984c..9ea70ff4bfcb37f2a6c08648857332dfd44282af 100644 (file)
@@ -31,7 +31,7 @@ public class Pipedot extends BasicSupport {
                List<Story> list = new ArrayList<Story>();
 
                URL url = new URL("https://pipedot.org/");
-               InputStream in = open(url);
+               InputStream in = downloader.open(url);
                Document doc = DataUtil.load(in, "UTF-8", url.toString());
                Elements articles = doc.getElementsByClass("story");
                for (Element article : articles) {
@@ -70,9 +70,38 @@ public class Pipedot extends BasicSupport {
                        String details = "";
                        Elements detailsElements = article.getElementsByTag("div");
                        if (detailsElements.size() > 0) {
-                               details = detailsElements.get(0).text();
+                               details = detailsElements.get(0).text().trim();
                        }
 
+                       String author = "";
+                       int pos = details.indexOf("by ");
+                       if (pos >= 0) {
+                               author = details.substring(pos + "by ".length()).trim();
+                               pos = author.indexOf(" in ");
+                               if (pos >= 0) {
+                                       author = author.substring(0, pos).trim();
+                               }
+                       }
+
+                       String categ = "";
+                       pos = details.indexOf(" in ");
+                       if (pos >= 0) {
+                               categ = details.substring(pos + " in ".length()).trim();
+                               pos = categ.indexOf(" on ");
+                               if (pos >= 0) {
+                                       categ = categ.substring(0, pos).trim();
+                               }
+                       }
+
+                       String date = "";
+                       Element dateElement = article.getElementsByTag("time").first();
+                       if (dateElement != null) {
+                               date = date(dateElement.attr("datetime"));
+                       }
+
+                       // We already have all the details (date, author, id, categ)
+                       details = "";
+
                        String body = "";
                        for (Element elem : article.children()) {
                                String tag = elem.tag().toString();
@@ -82,8 +111,8 @@ public class Pipedot extends BasicSupport {
                                }
                        }
 
-                       list.add(new Story(getType(), id, title.text(), details, intUrl,
-                                       extUrl, body));
+                       list.add(new Story(getType(), id, title.text(), author, date,
+                                       categ, details, intUrl, extUrl, body));
                }
 
                return list;
@@ -94,7 +123,7 @@ public class Pipedot extends BasicSupport {
                List<Comment> comments = new ArrayList<Comment>();
 
                URL url = new URL(story.getUrlInternal());
-               InputStream in = open(url);
+               InputStream in = downloader.open(url);
                Document doc = DataUtil.load(in, "UTF-8", url.toString());
                Elements listing = doc.getElementsByTag("main");
                if (listing.size() > 0) {
@@ -142,12 +171,7 @@ public class Pipedot extends BasicSupport {
        }
 
        private List<String> toLines(Element element) {
-               return toLines(element, new QuoteProcessor() {
-                       @Override
-                       public String processText(String text) {
-                               return text;
-                       }
-
+               return toLines(element, new BasicElementProcessor() {
                        @Override
                        public boolean detectQuote(Node node) {
                                if (node instanceof Element) {
@@ -160,16 +184,6 @@ public class Pipedot extends BasicSupport {
 
                                return false;
                        }
-
-                       @Override
-                       public boolean ignoreNode(Node node) {
-                               return false;
-                       }
-
-                       @Override
-                       public String manualProcessing(Node node) {
-                               return null;
-                       }
                });
        }
 }