Small fixes in different places
authorNiki Roo <niki@nikiroo.be>
Fri, 23 Mar 2018 22:49:42 +0000 (23:49 +0100)
committerNiki Roo <niki@nikiroo.be>
Fri, 23 Mar 2018 22:49:42 +0000 (23:49 +0100)
src/be/nikiroo/gofetch/support/BasicSupport.java
src/be/nikiroo/gofetch/support/LWN.java
src/be/nikiroo/gofetch/support/Pipedot.java
src/be/nikiroo/gofetch/support/Slashdot.java
src/be/nikiroo/gofetch/support/TheRegister.java

index b0325b39db59ebbdbfffe1af6654ad208f101189..8fc259a19daa84d387edb1a14b3b9d2adf7583b2 100644 (file)
@@ -435,7 +435,7 @@ public abstract class BasicSupport {
 
                long epoch = 0;
                try {
-                       epoch = Long.parseLong(date);
+                       epoch = Long.parseLong(date.trim());
                } catch (Exception e) {
                        epoch = 0;
                }
index 37a5a8f2fefcf8a88b71228e3ee62db01b88a86a..c033104f92fed7e7a81a5673894c0463a8d0608e 100644 (file)
@@ -64,7 +64,7 @@ public class LWN extends BasicSupport {
                        String categ = "";
                        pos = details.indexOf("]");
                        if (pos >= 0) {
-                               categ = details.substring(1, pos + 1).trim();
+                               categ = details.substring(1, pos).trim();
                        }
 
                        String author = "";
@@ -77,9 +77,9 @@ public class LWN extends BasicSupport {
                        pos = details.indexOf(" Posted ");
                        if (pos >= 0) {
                                date = details.substring(pos + " Posted ".length()).trim();
-                               pos = details.indexOf(" by ");
+                               pos = date.indexOf(" by ");
                                if (pos >= 0) {
-                                       author = details.substring(0, pos).trim();
+                                       date = date.substring(0, pos).trim();
                                }
                        }
 
index edbb8047df8f57b18661ff8b15a0ffb62e0f70f2..9ea70ff4bfcb37f2a6c08648857332dfd44282af 100644 (file)
@@ -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;
index 4746cc2eacfb28b41d3983ae6baddd34e5939dd0..b3a779da62d229469346f8a9455b1e01b160ab9d 100644 (file)
@@ -49,8 +49,8 @@ public class Slashdot extends BasicSupport {
                        }
 
                        Elements links = title.getElementsByTag("a");
-                       String intUrl = null;
-                       String extUrl = null;
+                       String intUrl = "";
+                       String extUrl = "";
                        if (links.size() > 0) {
                                intUrl = links.get(0).absUrl("href");
                        }
@@ -92,6 +92,9 @@ public class Slashdot extends BasicSupport {
                        Element dateElement = doc.getElementsByTag("time").first();
                        if (dateElement != null) {
                                date = StringUtils.unhtml(dateElement.text()).trim();
+                               if (date.startsWith("on ")) {
+                                       date = date.substring("on ".length());
+                               }
                        }
 
                        list.add(new Story(getType(), id, title.text(), author, date,
index 5903eaa64a2b8512712eb623290deed4db244db5..7fb152400f11a641193e47ddd78d2287baef81fb 100644 (file)
@@ -85,6 +85,9 @@ public class TheRegister extends BasicSupport {
                                details += StringUtils.unhtml(detailsElement.text()).trim();
                        }
 
+                       // We have some "details" but no content, so we switch them:
+                       body = details;
+                       details = "";
                        list.add(new Story(getType(), id, title, author, date, categ,
                                        details, intUrl, extUrl, body));
                }