package pnews;
-import java.util.Date;
+import java.time.Instant;
import java.util.concurrent.atomic.AtomicLong;
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;
return false;
}
- public Date getPublicationDate() {
+ public Instant getPublicationDate() {
return publicationDate;
}
}
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;
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;
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 {
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) {
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);
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;
import javax.json.JsonString;
import javax.json.JsonValue;
+import pnews.Article;
import pnews.Category;
import pnews.Feed;
import pnews.Language;
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;
}
"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"],