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.List;
13 import com.rometools.rome.feed.synd.SyndEnclosure;
14 import com.rometools.rome.feed.synd.SyndEntry;
15 import com.rometools.rome.feed.synd.SyndFeed;
16 import com.rometools.rome.io.FeedException;
17 import com.rometools.rome.io.SyndFeedInput;
18 import com.rometools.rome.io.XmlReader;
23 private static void addArticles(Category cat, SyndFeed feed, List<Article> articles) {
27 for (SyndEntry entry: feed.getEntries()) {
29 for (SyndEnclosure e: entry.getEnclosures()) {
30 if (e.getType().startsWith("image/"))
31 thumbnail = e.getUrl();
37 desc = Jsoup.parse(entry.getDescription().getValue()).text();
39 articles.add(new Article(entry.getLink(),
47 private static SyndFeed getSyndFeed(String u) throws IllegalArgumentException, FeedException, MalformedURLException, IOException {
48 try (XmlReader reader = new XmlReader(new URL(u))) {
49 return new SyndFeedInput().build(reader);
53 private static List<Article> getArticles(Category cat) throws IllegalArgumentException, MalformedURLException, FeedException, IOException {
54 List<Article> articles;
56 articles = new ArrayList<>();
60 addArticles(cat, getSyndFeed("http://www.france24.com/fr/actualites/rss"), articles);
61 addArticles(cat, getSyndFeed("http://www.bfmtv.com/rss/info/flux-rss/flux-toutes-les-actualites/"), articles);
64 addArticles(cat, getSyndFeed("http://www.france24.com/fr/sports/rss"), articles);
67 addArticles(cat, getSyndFeed("http://www.france24.com/fr/france/rss"), articles);
70 addArticles(cat, getSyndFeed("http://www.france24.com/fr/europe/rss"), articles);
73 addArticles(cat, getSyndFeed("http://www.france24.com/fr/economie/rss"), articles);
76 throw new IllegalArgumentException();
82 private static void writeHTMLFile(Category cat) throws IllegalArgumentException, MalformedURLException, FeedException, IOException {
83 List<Article> articles;
87 articles = getArticles(cat);
89 html = HTML.toHTML(articles);
91 f = new File(cat.getId() + ".html");
93 try (BufferedWriter writer = Files.newBufferedWriter(f.toPath(), StandardCharsets.UTF_8)) {
98 public static void main(String[] args) throws IllegalArgumentException, FeedException, IOException {
99 System.out.println("pnews");
101 for (Category cat: Category.values())
104 System.out.println("done");