3 import java.io.BufferedWriter;
5 import java.io.IOException;
6 import java.net.MalformedURLException;
8 import java.nio.charset.StandardCharsets;
9 import java.nio.file.Files;
10 import java.util.ArrayList;
11 import java.util.Comparator;
12 import java.util.List;
14 import com.rometools.rome.feed.synd.SyndEnclosure;
15 import com.rometools.rome.feed.synd.SyndEntry;
16 import com.rometools.rome.feed.synd.SyndFeed;
17 import com.rometools.rome.io.FeedException;
18 import com.rometools.rome.io.SyndFeedInput;
19 import com.rometools.rome.io.XmlReader;
20 import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils.Collections;
26 private static void addArticles(Category cat, SyndFeed feed, List<Article> articles) {
30 for (SyndEntry entry: feed.getEntries()) {
32 for (SyndEnclosure e: entry.getEnclosures()) {
33 if (e.getType().startsWith("image/"))
34 thumbnail = e.getUrl();
40 desc = Jsoup.parse(entry.getDescription().getValue()).text();
42 articles.add(new Article(entry.getLink(),
47 entry.getPublishedDate(),
52 private static SyndFeed getSyndFeed(String u) throws IllegalArgumentException, FeedException, MalformedURLException, IOException {
53 try (XmlReader reader = new XmlReader(new URL(u))) {
54 return new SyndFeedInput().build(reader);
58 private static List<Article> getArticles(Category cat) throws IllegalArgumentException, MalformedURLException, FeedException, IOException {
59 List<Article> articles;
61 articles = new ArrayList<>();
65 addArticles(cat, getSyndFeed("http://www.france24.com/fr/actualites/rss"), articles);
66 addArticles(cat, getSyndFeed("http://www.bfmtv.com/rss/info/flux-rss/flux-toutes-les-actualites/"), articles);
69 addArticles(cat, getSyndFeed("http://www.france24.com/fr/sports/rss"), articles);
72 addArticles(cat, getSyndFeed("http://www.france24.com/fr/france/rss"), articles);
75 addArticles(cat, getSyndFeed("http://www.france24.com/fr/europe/rss"), articles);
78 addArticles(cat, getSyndFeed("http://www.france24.com/fr/economie/rss"), articles);
81 throw new IllegalArgumentException();
84 articles.sort(new Comparator<Article> () {
86 public int compare(Article o1, Article o2) {
87 return o2.publicationDate.compareTo(o1.publicationDate);
94 private static void writeHTMLFile(Category cat) throws IllegalArgumentException, MalformedURLException, FeedException, IOException {
95 List<Article> articles;
99 articles = getArticles(cat);
101 html = HTML.toHTML(articles);
103 f = new File(cat.getId() + ".html");
105 try (BufferedWriter writer = Files.newBufferedWriter(f.toPath(), StandardCharsets.UTF_8)) {
110 public static void main(String[] args) throws IllegalArgumentException, FeedException, IOException {
111 System.out.println("pnews");
113 for (Category cat: Category.values())
116 System.out.println("done");