- public static void main(String[] args) throws IllegalArgumentException, FeedException, IOException {
- URL url;
- String html;
- List<SyndFeed> feeds;
- SyndFeed feed;
- String[] urls = new String[] {
- "http://www.france24.com/fr/france/rss",
- "https://www.lesechos.fr/rss/rss_une_titres.xml"
- };
-
+ private static SyndFeed getSyndFeed(String u) throws IllegalArgumentException, FeedException, MalformedURLException, IOException {
+ try (XmlReader reader = new XmlReader(new URL(u))) {
+ return new SyndFeedInput().build(reader);
+ }
+ }
+
+ private static List<Article> getArticles(Category cat) throws IllegalArgumentException, MalformedURLException, FeedException, IOException {
+ List<Article> articles;
+
+ articles = new ArrayList<>();
+
+ switch (cat) {
+ case TOP:
+ addArticles(cat, getSyndFeed("http://www.france24.com/fr/actualites/rss"), articles);
+ addArticles(cat, getSyndFeed("http://www.bfmtv.com/rss/info/flux-rss/flux-toutes-les-actualites/"), articles);
+ break;
+ case SPORT:
+ addArticles(cat, getSyndFeed("http://www.france24.com/fr/sports/rss"), articles);
+ break;
+ case FRANCE:
+ addArticles(cat, getSyndFeed("http://www.france24.com/fr/france/rss"), articles);
+ break;
+ case EUROPE:
+ addArticles(cat, getSyndFeed("http://www.france24.com/fr/europe/rss"), articles);
+ break;
+ case ECO:
+ addArticles(cat, getSyndFeed("http://www.france24.com/fr/economie/rss"), articles);
+ break;
+ default:
+ throw new IllegalArgumentException();
+ }
+
+ return articles;
+ }
+
+ private static void writeHTMLFile(Category cat) throws IllegalArgumentException, MalformedURLException, FeedException, IOException {
+ List<Article> articles;
+ String html;
+ File f;
+
+ articles = getArticles(cat);
+
+ html = HTML.toHTML(articles);
+
+ f = new File(cat.getId() + ".html");
+
+ try (BufferedWriter writer = Files.newBufferedWriter(f.toPath(), StandardCharsets.UTF_8)) {
+ writer.write(html);
+ }
+ }
+
+ public static void main(String[] args) throws IllegalArgumentException, FeedException, IOException {