do not load articles older than 60 days
authorJean-Philippe Orsini <orsinije@fr.ibm.com>
Sun, 5 Nov 2017 21:35:51 +0000 (22:35 +0100)
committerJean-Philippe Orsini <orsinije@fr.ibm.com>
Sun, 5 Nov 2017 21:35:51 +0000 (22:35 +0100)
war/src/main/java/pnews/Article.java
war/src/main/java/pnews/servlet/ArticleProvider.java
war/src/main/java/pnews/servlet/Config.java
war/src/main/resources/feeds.json

index 97e8b76..5b2e21c 100644 (file)
@@ -1,6 +1,6 @@
 package pnews;
 
-import java.util.Date;
+import java.time.Instant;
 import java.util.concurrent.atomic.AtomicLong;
 
 public class Article {
@@ -8,12 +8,12 @@ public class Article {
         public final String description;
         public final String thumbnail;
         public final String link;
-        public final Date publicationDate;
+        public final Instant publicationDate;
         public final String website;
         public final String[] entities;
         public final AtomicLong readCount = new AtomicLong();
         
-        public Article(String link, String title, String description, String thumbnail, Date publicationDate, String website, String[] entities) {
+        public Article(String link, String title, String description, String thumbnail, Instant publicationDate, String website, String[] entities) {
                 this.link = link;
                 this.title = title;
                 this.description = description;
@@ -35,7 +35,7 @@ public class Article {
                 return false;
         }
         
-        public Date getPublicationDate() {
+        public Instant getPublicationDate() {
                 return publicationDate;
         }
 }
index ec74123..5d4959b 100644 (file)
@@ -3,6 +3,7 @@ package pnews.servlet;
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.time.Instant;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
@@ -74,7 +75,20 @@ public class ArticleProvider {
                 return false;
         }
         
-        private Article toArticle(String link, SyndEntry entry, SyndFeed feed, String lang) {
+        private Instant getArticleInstant(SyndEntry entry) {
+                Date date;
+                
+                date = entry.getUpdatedDate();       
+                if (date == null)
+                        date = entry.getPublishedDate();
+
+                if (date == null)
+                        return Instant.now();
+                
+                return date.toInstant();
+        }
+        
+        private Article toArticle(String link, SyndEntry entry, SyndFeed feed, String lang, Instant instant) {
                 String desc, title, thumbnail, feedTitle, str;
                 Date date;
                 List<String> entities;
@@ -100,14 +114,7 @@ public class ArticleProvider {
                         desc = null;
                         LOG.severe("No description for " + feedTitle + " - " + title);
                 }
-                
-                date = entry.getPublishedDate();
-                if (date == null)
-                        date = entry.getUpdatedDate();
-                if (date == null)
-                        LOG.severe("The article " + feedTitle + " - " + title + " does not have a date");
-                                     
-                
+                                
                 entities = new ArrayList<>();
                 if (desc != null && lang.equals("en"))
                         try {
@@ -117,7 +124,7 @@ public class ArticleProvider {
                                 LOG.log(Level.SEVERE, "Cannot classify " + feedTitle, e1);                         
                         }
                 
-                return new Article(link, title, desc, thumbnail, date, feedTitle, entities.toArray(new String[0]));
+                return new Article(link, title, desc, thumbnail, instant, feedTitle, entities.toArray(new String[0]));
         }
         
         private void addArticles(Category cat, SyndFeed feed) {
@@ -137,7 +144,12 @@ public class ArticleProvider {
                                 continue ;
                         }
                         
-                        a = ArticleStore.singleton.getArticle(link, ()->toArticle(link, entry, feed, cat.getLanguage()));
+                        final Instant instant = getArticleInstant(entry);
+                        
+                        if (config.isObsolete(instant))
+                                continue ;
+                        
+                        a = ArticleStore.singleton.getArticle(link, ()->toArticle(link, entry, feed, cat.getLanguage(), instant));
                         
                         synchronized (articles) {
                                 articles.add(a);
index 46e75f6..36bdc62 100644 (file)
@@ -4,6 +4,9 @@ import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.Reader;
 import java.io.UnsupportedEncodingException;
+import java.time.Instant;
+import java.time.temporal.ChronoUnit;
+import java.time.temporal.TemporalUnit;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -19,6 +22,7 @@ import javax.json.JsonObject;
 import javax.json.JsonString;
 import javax.json.JsonValue;
 
+import pnews.Article;
 import pnews.Category;
 import pnews.Feed;
 import pnews.Language;
@@ -180,6 +184,17 @@ public class Config {
                 return result;
         }
         
+        public boolean isObsolete(Instant instant) {
+                Instant olderInstant;
+                
+                olderInstant = Instant.now().minus(60, ChronoUnit.DAYS);
+                
+                if (instant.isAfter(olderInstant))
+                        return false;
+                else
+                        return true;
+        }
+        
         public Feed[] getFeeds() {
                 return feeds;
         }
index b10615c..03d4217 100644 (file)
                 "http://www.markshuttleworth.com/feed": { "categories": ["en_linux"]},
                 "https://insights.ubuntu.com/feed/": { "categories": ["en_linux"]},
                 "http://feeds.feedburner.com/LinuxJournal-BreakingNews?format=xml": { "categories": ["en_linux"]},
+                "https://www.ossblog.org/feed/": { "categories": ["en_linux"]},
                 "https://www.gnome.org/feed/": { "categories": ["en_linux"]},
                 "http://linuxreviews.org/en.rss": { "categories": ["en_linux"]},
                 "http://www.linux-magazine.com/rss/feed/lmi_news": { "categories": ["en_linux"]},
                         "Digital Trends",
                         "Joey Sneddon",
                         "CA",
-                        "Read"
+                        "Read",
+                        "5 :",
+                        "InfoWorld"
                 ],
                 "aliases": {
                         "U.S.": ["United States", "US"],