moved to a subdir
authorJean-Philippe Orsini <orsinije@fr.ibm.com>
Thu, 12 Oct 2017 07:06:11 +0000 (09:06 +0200)
committerJean-Philippe Orsini <orsinije@fr.ibm.com>
Thu, 12 Oct 2017 07:06:11 +0000 (09:06 +0200)
18 files changed:
.gitignore [deleted file]
pnews/.gitignore [new file with mode: 0644]
pnews/pom.xml [new file with mode: 0644]
pnews/run.sh [new file with mode: 0755]
pnews/src/main/java/pnews/Article.java [new file with mode: 0644]
pnews/src/main/java/pnews/Category.java [new file with mode: 0644]
pnews/src/main/java/pnews/HTML.java [new file with mode: 0644]
pnews/src/main/java/pnews/Main.java [new file with mode: 0644]
pnews/src/main/scripts/pnews.sh [new file with mode: 0755]
pnews/style.css [new file with mode: 0644]
pom.xml [deleted file]
run.sh [deleted file]
src/main/java/pnews/Article.java [deleted file]
src/main/java/pnews/Category.java [deleted file]
src/main/java/pnews/HTML.java [deleted file]
src/main/java/pnews/Main.java [deleted file]
src/main/scripts/pnews.sh [deleted file]
style.css [deleted file]

diff --git a/.gitignore b/.gitignore
deleted file mode 100644 (file)
index 2061c9e..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-target
-.classpath
-.project
diff --git a/pnews/.gitignore b/pnews/.gitignore
new file mode 100644 (file)
index 0000000..2061c9e
--- /dev/null
@@ -0,0 +1,3 @@
+target
+.classpath
+.project
diff --git a/pnews/pom.xml b/pnews/pom.xml
new file mode 100644 (file)
index 0000000..5631d03
--- /dev/null
@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project>
+        <modelVersion>4.0.0</modelVersion>
+        <groupId>pnews</groupId>
+        <artifactId>pnews</artifactId>
+        <version>1.0</version>
+        <packaging>jar</packaging>
+        <name>pnews</name>
+
+        <properties>
+                <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+                <maven.compiler.source>1.8</maven.compiler.source>
+                <maven.compiler.target>1.8</maven.compiler.target>
+        </properties>
+
+        <dependencies>
+                <dependency>
+                        <groupId>com.rometools</groupId>
+                        <artifactId>rome</artifactId>
+                        <version>1.8.0</version>
+                </dependency>
+                <dependency>
+                        <groupId>org.jsoup</groupId>
+                        <artifactId>jsoup</artifactId>
+                        <version>1.10.3</version>
+                </dependency>
+        </dependencies>
+
+        <build>
+                <plugins>
+                        <plugin>
+                                <groupId>org.apache.maven.plugins</groupId>
+                                <artifactId>maven-dependency-plugin</artifactId>
+                                <version>2.10</version>
+                                <executions>
+                                        <execution>
+                                                <id>copy-dependencies</id>
+                                                <phase>package</phase>
+                                                <goals>
+                                                        <goal>copy-dependencies</goal>
+                                                </goals>
+                                                <configuration>
+                                                        <outputDirectory>${project.build.directory}</outputDirectory>
+                                                        <overWriteReleases>false</overWriteReleases>
+                                                </configuration>
+                                        </execution>
+                                </executions>
+                        </plugin>
+                        <plugin>
+                                <artifactId>maven-resources-plugin</artifactId>
+                                <version>3.0.1</version>
+                                <executions>
+                                        <execution>
+                                                <id>copy-resources</id>
+                                                <phase>process-resources</phase>
+                                                <goals>
+                                                        <goal>copy-resources</goal>
+                                                </goals>
+                                                <configuration>
+                                                        <outputDirectory>${basedir}/target/</outputDirectory>
+                                                        <resources>
+                                                                <resource>
+                                                                        <directory>src/main/scripts</directory>
+                                                                        <filtering>true</filtering>
+                                                                </resource>
+                                                        </resources>
+                                                </configuration>
+                                        </execution>
+                                </executions>
+                        </plugin>
+                        <plugin>
+                                <groupId>org.apache.maven.plugins</groupId>
+                                <artifactId>maven-jar-plugin</artifactId>
+                                <version>3.0.2</version>
+                                <configuration>
+                                        <archive>
+                                                <manifest>
+                                                        <addClasspath>true</addClasspath>
+                                                        <mainClass>pnews.Main</mainClass>
+                                                </manifest>
+                                        </archive>
+                                </configuration>
+                        </plugin>
+                        <plugin>
+                                <groupId>org.apache.maven.plugins</groupId>
+                                <artifactId>maven-antrun-plugin</artifactId>
+                                <version>1.6</version>
+                                <executions>
+                                        <execution>
+                                                <id>fix-shell-permissions</id>
+                                                <phase>process-resources</phase>
+                                                <configuration>
+                                                        <target>
+                                                                <chmod file="target/pnews.sh" perm="755"/>
+                                                        </target>
+                                                </configuration>
+                                                <goals>
+                                                        <goal>run</goal>
+                                                </goals>
+                                        </execution>
+                                </executions>
+                        </plugin>
+                </plugins>
+          </build>
+</project>
diff --git a/pnews/run.sh b/pnews/run.sh
new file mode 100755 (executable)
index 0000000..ede7e9b
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+set -e
+
+DEST_DIR=`realpath $1`
+TMP_DIR="/tmp/$$.tmp"
+
+mkdir -p "$TMP_DIR"
+
+cd $TMP_DIR
+git clone https://git.wpitchoune.net/pnews.git
+
+cd pnews
+
+mvn clean install
+
+target/pnews.sh
+
+cp -p *html style.css $DEST_DIR
+
+rm -rf "$TMP_DIR"
diff --git a/pnews/src/main/java/pnews/Article.java b/pnews/src/main/java/pnews/Article.java
new file mode 100644 (file)
index 0000000..0b54205
--- /dev/null
@@ -0,0 +1,23 @@
+package pnews;
+
+import java.util.Date;
+
+public class Article {
+        public final String title;
+        public final String description;
+        public final String thumbnail;
+        public final String link;
+        public final Category category;
+        public final Date publicationDate;
+        public final String website;
+        
+        public Article(String link, Category category, String title, String description, String thumbnail, Date publicationDate, String website) {
+                this.link = link;
+                this.title = title;
+                this.description = description;
+                this.thumbnail = thumbnail;
+                this.category = category;
+                this.publicationDate = publicationDate;
+                this.website = website;
+        }
+}
diff --git a/pnews/src/main/java/pnews/Category.java b/pnews/src/main/java/pnews/Category.java
new file mode 100644 (file)
index 0000000..efabe5e
--- /dev/null
@@ -0,0 +1,21 @@
+package pnews;
+
+public enum Category {
+        TOP("top"),
+        FRANCE("france"),
+        SPORT("sport"),
+        EUROPE("europe"),
+        ECO("eco"),
+        ESSONNE("essonne"),
+        TECHNOLOGIE("technologie");
+        
+        private final String id;
+                
+        private Category(String id) {
+                this.id = id;
+        }
+        
+        public String getId() {
+                return id;
+        }
+}
diff --git a/pnews/src/main/java/pnews/HTML.java b/pnews/src/main/java/pnews/HTML.java
new file mode 100644 (file)
index 0000000..78d584d
--- /dev/null
@@ -0,0 +1,100 @@
+package pnews;
+
+import java.util.List;
+
+public class HTML {
+       private static void appendA(StringBuffer buf, String child, String href, String cl) {
+               buf.append("<a href='");
+               buf.append(href);
+               buf.append("'");
+               if (cl != null) {
+                       buf.append(" class='");
+                       buf.append(cl);
+                       buf.append('\'');
+               }
+               buf.append('>');
+               buf.append(child);
+               buf.append("</a>");
+       }
+       
+       private static void appendDiv(StringBuffer buf, String child) {
+               buf.append("<div>");
+               buf.append(child);
+               buf.append("</div>\n");
+       }
+       
+       private static void appendP(StringBuffer buf, String child) {
+               buf.append("<p>");
+               buf.append(child);
+               buf.append("</p>\n");
+       }
+       
+       private static void append(StringBuffer buf, Article a) {               
+               buf.append("<div class='article'>\n");
+               
+               buf.append("<h2>");
+               if (a.thumbnail != null) {
+                       buf.append("<img class='left' src='");
+                       buf.append(a.thumbnail);
+                       buf.append("'/>\n");
+               }
+               appendA(buf, a.title, a.link, null);
+               buf.append("</h2>\n");
+               
+               buf.append("<div class='article-info'>" + a.website + " - " + a.publicationDate + "</div>");
+               
+               if (a.description != null) {
+                       buf.append("<p>");
+                       buf.append(a.description);
+                       buf.append("</p>");
+               }
+               
+               buf.append("</div>\n");         
+       }
+       
+       private static void appendMenu(StringBuffer buf, Category catActive) {
+               String cl;
+               
+               buf.append("<nav>\n");
+               buf.append("<ul>\n");
+
+               for (Category cat: Category.values()) {
+                       buf.append("<li>");
+                       
+                       if (cat.equals(catActive))
+                               cl = "active";
+                       else
+                               cl = null;
+                       
+                       appendA(buf, cat.getId(), cat.getId() + ".html", cl);
+                       buf.append("</li>");
+               }
+               
+               buf.append("</ul>\n");
+               buf.append("</nav>\n");
+       }
+       
+       public static String toHTML(List<Article> articles, Category catActive) {
+               StringBuffer buf;
+               
+               buf = new StringBuffer();
+               buf.append("<!DOCTYPE html>\n");
+               buf.append("<html lang='fr'>\n");
+               buf.append("<head>\n");
+               buf.append("<meta charset=\"UTF-8\">\n");
+               buf.append("<link rel='stylesheet' href='style.css' />\n");
+               buf.append("<title>PNews</title>\n");
+               buf.append("</head>\n");
+               buf.append("<body>\n");
+               
+               appendMenu(buf, catActive);
+               
+               for (Article e: articles)
+                       append(buf, e);
+               
+               buf.append("</body>\n");
+               buf.append("</html>\n");
+       
+               return buf.toString();
+       }
+}
diff --git a/pnews/src/main/java/pnews/Main.java b/pnews/src/main/java/pnews/Main.java
new file mode 100644 (file)
index 0000000..6086a74
--- /dev/null
@@ -0,0 +1,203 @@
+package pnews;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Logger;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+
+import org.jsoup.Jsoup;
+
+import com.rometools.rome.feed.synd.SyndEnclosure;
+import com.rometools.rome.feed.synd.SyndEntry;
+import com.rometools.rome.feed.synd.SyndFeed;
+import com.rometools.rome.io.FeedException;
+import com.rometools.rome.io.SyndFeedInput;
+import com.rometools.rome.io.XmlReader;
+
+public class Main {
+        private static final Logger LOG = Logger.getLogger(Main.class.getName());
+        
+        static {
+                TrustManager[] mgrs;
+                SSLContext sc;
+                
+                mgrs = new TrustManager[]{
+                                new X509TrustManager() {
+                                        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
+                                                return null;
+                                        }
+
+                                        public void checkClientTrusted(X509Certificate[] certs, String authType) {
+                                        }
+
+                                        public void checkServerTrusted(X509Certificate[] certs, String authType) {
+                                        }
+                                }
+                };
+
+                try {
+                        sc = SSLContext.getInstance("SSL");
+
+                        sc.init(null, mgrs, new java.security.SecureRandom());
+                        SSLContext.setDefault(sc);
+                } catch (NoSuchAlgorithmException | KeyManagementException e) {
+                        e.printStackTrace();
+                }
+        }
+        
+       private static void addArticles(Category cat, SyndFeed feed, List<Article> articles) {
+               String thumbnail;
+               String desc;
+               Date date;              
+               
+               for (SyndEntry entry: feed.getEntries()) {
+                       thumbnail = null;
+                       for (SyndEnclosure e: entry.getEnclosures()) {
+                               if (e.getType().startsWith("image/"))
+                                       thumbnail = e.getUrl();    
+                               break;
+                       }
+                               
+                       if (entry.getDescription() != null) {                             
+                               desc = Jsoup.parse(entry.getDescription().getValue()).text();
+                       } else {       
+                               desc = null;
+                               LOG.severe("No description for " + feed.getTitle() + " - " + entry.getTitle());
+                       }
+                       
+                       date = entry.getPublishedDate();
+                       if (date == null)
+                               date = entry.getUpdatedDate();
+                       
+                       articles.add(new Article(entry.getLink(),
+                                                cat,
+                                                entry.getTitle(),
+                                                desc,
+                                                thumbnail,
+                                                date,
+                                                feed.getTitle()));
+                }               
+       }
+       
+       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 Map<Category, String[]> getFeeds() {
+               Map<Category, String[]> result;
+               
+               result = new HashMap<>();
+               
+               result.put(Category.TOP,
+                          new String[] {
+                                          "http://www.francetvinfo.fr/titres.rss",
+                                          "http://www.france24.com/fr/actualites/rss",
+                                          "https://www.franceinter.fr/rss/a-la-une.xml",
+                                          "http://www.rfi.fr/general/rss",
+                                          "http://www.cnews.fr/rss/une",
+                                          "http://www.bfmtv.com/rss/info/flux-rss/flux-toutes-les-actualites/"
+                          });
+               
+               result.put(Category.SPORT,
+                               new String[] { "http://www.france24.com/fr/sports/rss" });
+               
+               result.put(Category.FRANCE,
+                                new String[] { "http://www.france24.com/fr/france/rss",
+                                               "http://www.rfi.fr/france/rss"});
+               
+               result.put(Category.EUROPE,
+                                new String[] { "http://www.france24.com/fr/europe/rss" });
+               
+               result.put(Category.ECO,
+                                new String[] { "http://www.france24.com/fr/economie/rss",
+                                               "http://www.rfi.fr/economie/rss" });
+               
+               result.put(Category.ESSONNE,
+                                new String[] { "https://www.essonneinfo.fr/feed/" });
+               
+               result.put(Category.TECHNOLOGIE,
+                                new String[] { "http://feeds.feedburner.com/lesnumeriques/news",
+                                               "http://www.zdnet.fr/feeds/rss/actualites/"});
+               
+               return result;
+       }
+       
+       private static List<Article> getArticles(Category cat) throws IllegalArgumentException, MalformedURLException, FeedException, IOException {
+               List<Article> articles;
+               String[] feeds;
+               Set<String> links;
+               
+               articles = new ArrayList<>();
+               
+               feeds = getFeeds().get(cat);
+               
+               if (feeds != null)
+                       for (String str: feeds)
+                               addArticles(cat, getSyndFeed(str), articles);
+               else
+                       LOG.severe("No feed for category " + cat);
+
+               links = new HashSet<>(articles.size());
+               for (Article a: articles) {
+                       if (links.contains(a.link))
+                               LOG.severe(a.link + "is not uniq");
+                       else
+                               links.add(a.link);
+               }
+               
+               articles.sort(new Comparator<Article> () {
+                        @Override
+                        public int compare(Article o1, Article o2) {
+                                return o2.publicationDate.compareTo(o1.publicationDate);
+                        }                      
+               });
+               
+               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, cat);
+               
+               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 {                            
+               System.out.println("pnews");
+               
+               for (Category cat: Category.values())
+                       writeHTMLFile(cat);
+               
+               System.out.println("done");
+       }
+}
\ No newline at end of file
diff --git a/pnews/src/main/scripts/pnews.sh b/pnews/src/main/scripts/pnews.sh
new file mode 100755 (executable)
index 0000000..fbad98b
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+set -e
+
+SDIR=`dirname $0`
+
+java -classpath rome-1.8.0.jar -jar $SDIR/pnews-1.0.jar
diff --git a/pnews/style.css b/pnews/style.css
new file mode 100644 (file)
index 0000000..cc79235
--- /dev/null
@@ -0,0 +1,74 @@
+a {
+        text-decoration: none;
+        color: black;
+}
+
+body {
+        margin: 0 0 0 0;
+        padding: 1em 1em 1em 1em;
+        background-color: #eee;
+        font-family: sans-serif;
+        font-size: 100%;
+}
+
+nav {
+        font-size: 125%;
+        margin: 0 0 0 0;
+        padding: 0 0 0 0;
+}
+
+a.active {
+        text-decoration: none;
+        border-bottom: 4px solid black;
+}
+
+div {
+        margin: 0em 0em 0em 0em;
+        padding: 0 0 0 0;
+}
+
+div.article {
+        margin-bottom: 1em;
+}
+
+.article-info {
+        font-size: 80%;
+        color: #bbb;
+}
+
+img {
+        margin: 0em 1em 1em 0em;
+        padding: 0 0 0 0;
+        width: 8em;
+}
+
+p {
+        margin: 1em 1em 1em 1em;
+        padding: 0 0 0 0;
+}
+
+.left {
+        float: left;
+}
+
+h2 {
+        clear: left;
+        margin: 0 0 0 0;
+        padding: 0 0 0 0;
+}
+
+nav {
+        font-size: 120%;
+}
+
+nav ul {
+        list-style-type: none;
+        padding: 0 0 0 0;
+}
+
+nav ul li {
+        display: inline;
+        margin: 0em 1em 0 0;
+        padding: 0 0 0 0;
+        text-transform: uppercase;
+}
diff --git a/pom.xml b/pom.xml
deleted file mode 100644 (file)
index 5631d03..0000000
--- a/pom.xml
+++ /dev/null
@@ -1,105 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project>
-        <modelVersion>4.0.0</modelVersion>
-        <groupId>pnews</groupId>
-        <artifactId>pnews</artifactId>
-        <version>1.0</version>
-        <packaging>jar</packaging>
-        <name>pnews</name>
-
-        <properties>
-                <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-                <maven.compiler.source>1.8</maven.compiler.source>
-                <maven.compiler.target>1.8</maven.compiler.target>
-        </properties>
-
-        <dependencies>
-                <dependency>
-                        <groupId>com.rometools</groupId>
-                        <artifactId>rome</artifactId>
-                        <version>1.8.0</version>
-                </dependency>
-                <dependency>
-                        <groupId>org.jsoup</groupId>
-                        <artifactId>jsoup</artifactId>
-                        <version>1.10.3</version>
-                </dependency>
-        </dependencies>
-
-        <build>
-                <plugins>
-                        <plugin>
-                                <groupId>org.apache.maven.plugins</groupId>
-                                <artifactId>maven-dependency-plugin</artifactId>
-                                <version>2.10</version>
-                                <executions>
-                                        <execution>
-                                                <id>copy-dependencies</id>
-                                                <phase>package</phase>
-                                                <goals>
-                                                        <goal>copy-dependencies</goal>
-                                                </goals>
-                                                <configuration>
-                                                        <outputDirectory>${project.build.directory}</outputDirectory>
-                                                        <overWriteReleases>false</overWriteReleases>
-                                                </configuration>
-                                        </execution>
-                                </executions>
-                        </plugin>
-                        <plugin>
-                                <artifactId>maven-resources-plugin</artifactId>
-                                <version>3.0.1</version>
-                                <executions>
-                                        <execution>
-                                                <id>copy-resources</id>
-                                                <phase>process-resources</phase>
-                                                <goals>
-                                                        <goal>copy-resources</goal>
-                                                </goals>
-                                                <configuration>
-                                                        <outputDirectory>${basedir}/target/</outputDirectory>
-                                                        <resources>
-                                                                <resource>
-                                                                        <directory>src/main/scripts</directory>
-                                                                        <filtering>true</filtering>
-                                                                </resource>
-                                                        </resources>
-                                                </configuration>
-                                        </execution>
-                                </executions>
-                        </plugin>
-                        <plugin>
-                                <groupId>org.apache.maven.plugins</groupId>
-                                <artifactId>maven-jar-plugin</artifactId>
-                                <version>3.0.2</version>
-                                <configuration>
-                                        <archive>
-                                                <manifest>
-                                                        <addClasspath>true</addClasspath>
-                                                        <mainClass>pnews.Main</mainClass>
-                                                </manifest>
-                                        </archive>
-                                </configuration>
-                        </plugin>
-                        <plugin>
-                                <groupId>org.apache.maven.plugins</groupId>
-                                <artifactId>maven-antrun-plugin</artifactId>
-                                <version>1.6</version>
-                                <executions>
-                                        <execution>
-                                                <id>fix-shell-permissions</id>
-                                                <phase>process-resources</phase>
-                                                <configuration>
-                                                        <target>
-                                                                <chmod file="target/pnews.sh" perm="755"/>
-                                                        </target>
-                                                </configuration>
-                                                <goals>
-                                                        <goal>run</goal>
-                                                </goals>
-                                        </execution>
-                                </executions>
-                        </plugin>
-                </plugins>
-          </build>
-</project>
diff --git a/run.sh b/run.sh
deleted file mode 100755 (executable)
index ede7e9b..0000000
--- a/run.sh
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/bin/bash
-
-set -e
-
-DEST_DIR=`realpath $1`
-TMP_DIR="/tmp/$$.tmp"
-
-mkdir -p "$TMP_DIR"
-
-cd $TMP_DIR
-git clone https://git.wpitchoune.net/pnews.git
-
-cd pnews
-
-mvn clean install
-
-target/pnews.sh
-
-cp -p *html style.css $DEST_DIR
-
-rm -rf "$TMP_DIR"
diff --git a/src/main/java/pnews/Article.java b/src/main/java/pnews/Article.java
deleted file mode 100644 (file)
index 0b54205..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-package pnews;
-
-import java.util.Date;
-
-public class Article {
-        public final String title;
-        public final String description;
-        public final String thumbnail;
-        public final String link;
-        public final Category category;
-        public final Date publicationDate;
-        public final String website;
-        
-        public Article(String link, Category category, String title, String description, String thumbnail, Date publicationDate, String website) {
-                this.link = link;
-                this.title = title;
-                this.description = description;
-                this.thumbnail = thumbnail;
-                this.category = category;
-                this.publicationDate = publicationDate;
-                this.website = website;
-        }
-}
diff --git a/src/main/java/pnews/Category.java b/src/main/java/pnews/Category.java
deleted file mode 100644 (file)
index efabe5e..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-package pnews;
-
-public enum Category {
-        TOP("top"),
-        FRANCE("france"),
-        SPORT("sport"),
-        EUROPE("europe"),
-        ECO("eco"),
-        ESSONNE("essonne"),
-        TECHNOLOGIE("technologie");
-        
-        private final String id;
-                
-        private Category(String id) {
-                this.id = id;
-        }
-        
-        public String getId() {
-                return id;
-        }
-}
diff --git a/src/main/java/pnews/HTML.java b/src/main/java/pnews/HTML.java
deleted file mode 100644 (file)
index 78d584d..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-package pnews;
-
-import java.util.List;
-
-public class HTML {
-       private static void appendA(StringBuffer buf, String child, String href, String cl) {
-               buf.append("<a href='");
-               buf.append(href);
-               buf.append("'");
-               if (cl != null) {
-                       buf.append(" class='");
-                       buf.append(cl);
-                       buf.append('\'');
-               }
-               buf.append('>');
-               buf.append(child);
-               buf.append("</a>");
-       }
-       
-       private static void appendDiv(StringBuffer buf, String child) {
-               buf.append("<div>");
-               buf.append(child);
-               buf.append("</div>\n");
-       }
-       
-       private static void appendP(StringBuffer buf, String child) {
-               buf.append("<p>");
-               buf.append(child);
-               buf.append("</p>\n");
-       }
-       
-       private static void append(StringBuffer buf, Article a) {               
-               buf.append("<div class='article'>\n");
-               
-               buf.append("<h2>");
-               if (a.thumbnail != null) {
-                       buf.append("<img class='left' src='");
-                       buf.append(a.thumbnail);
-                       buf.append("'/>\n");
-               }
-               appendA(buf, a.title, a.link, null);
-               buf.append("</h2>\n");
-               
-               buf.append("<div class='article-info'>" + a.website + " - " + a.publicationDate + "</div>");
-               
-               if (a.description != null) {
-                       buf.append("<p>");
-                       buf.append(a.description);
-                       buf.append("</p>");
-               }
-               
-               buf.append("</div>\n");         
-       }
-       
-       private static void appendMenu(StringBuffer buf, Category catActive) {
-               String cl;
-               
-               buf.append("<nav>\n");
-               buf.append("<ul>\n");
-
-               for (Category cat: Category.values()) {
-                       buf.append("<li>");
-                       
-                       if (cat.equals(catActive))
-                               cl = "active";
-                       else
-                               cl = null;
-                       
-                       appendA(buf, cat.getId(), cat.getId() + ".html", cl);
-                       buf.append("</li>");
-               }
-               
-               buf.append("</ul>\n");
-               buf.append("</nav>\n");
-       }
-       
-       public static String toHTML(List<Article> articles, Category catActive) {
-               StringBuffer buf;
-               
-               buf = new StringBuffer();
-               buf.append("<!DOCTYPE html>\n");
-               buf.append("<html lang='fr'>\n");
-               buf.append("<head>\n");
-               buf.append("<meta charset=\"UTF-8\">\n");
-               buf.append("<link rel='stylesheet' href='style.css' />\n");
-               buf.append("<title>PNews</title>\n");
-               buf.append("</head>\n");
-               buf.append("<body>\n");
-               
-               appendMenu(buf, catActive);
-               
-               for (Article e: articles)
-                       append(buf, e);
-               
-               buf.append("</body>\n");
-               buf.append("</html>\n");
-       
-               return buf.toString();
-       }
-}
diff --git a/src/main/java/pnews/Main.java b/src/main/java/pnews/Main.java
deleted file mode 100644 (file)
index 6086a74..0000000
+++ /dev/null
@@ -1,203 +0,0 @@
-package pnews;
-
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.security.KeyManagementException;
-import java.security.NoSuchAlgorithmException;
-import java.security.cert.X509Certificate;
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.logging.Logger;
-
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.X509TrustManager;
-
-import org.jsoup.Jsoup;
-
-import com.rometools.rome.feed.synd.SyndEnclosure;
-import com.rometools.rome.feed.synd.SyndEntry;
-import com.rometools.rome.feed.synd.SyndFeed;
-import com.rometools.rome.io.FeedException;
-import com.rometools.rome.io.SyndFeedInput;
-import com.rometools.rome.io.XmlReader;
-
-public class Main {
-        private static final Logger LOG = Logger.getLogger(Main.class.getName());
-        
-        static {
-                TrustManager[] mgrs;
-                SSLContext sc;
-                
-                mgrs = new TrustManager[]{
-                                new X509TrustManager() {
-                                        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
-                                                return null;
-                                        }
-
-                                        public void checkClientTrusted(X509Certificate[] certs, String authType) {
-                                        }
-
-                                        public void checkServerTrusted(X509Certificate[] certs, String authType) {
-                                        }
-                                }
-                };
-
-                try {
-                        sc = SSLContext.getInstance("SSL");
-
-                        sc.init(null, mgrs, new java.security.SecureRandom());
-                        SSLContext.setDefault(sc);
-                } catch (NoSuchAlgorithmException | KeyManagementException e) {
-                        e.printStackTrace();
-                }
-        }
-        
-       private static void addArticles(Category cat, SyndFeed feed, List<Article> articles) {
-               String thumbnail;
-               String desc;
-               Date date;              
-               
-               for (SyndEntry entry: feed.getEntries()) {
-                       thumbnail = null;
-                       for (SyndEnclosure e: entry.getEnclosures()) {
-                               if (e.getType().startsWith("image/"))
-                                       thumbnail = e.getUrl();    
-                               break;
-                       }
-                               
-                       if (entry.getDescription() != null) {                             
-                               desc = Jsoup.parse(entry.getDescription().getValue()).text();
-                       } else {       
-                               desc = null;
-                               LOG.severe("No description for " + feed.getTitle() + " - " + entry.getTitle());
-                       }
-                       
-                       date = entry.getPublishedDate();
-                       if (date == null)
-                               date = entry.getUpdatedDate();
-                       
-                       articles.add(new Article(entry.getLink(),
-                                                cat,
-                                                entry.getTitle(),
-                                                desc,
-                                                thumbnail,
-                                                date,
-                                                feed.getTitle()));
-                }               
-       }
-       
-       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 Map<Category, String[]> getFeeds() {
-               Map<Category, String[]> result;
-               
-               result = new HashMap<>();
-               
-               result.put(Category.TOP,
-                          new String[] {
-                                          "http://www.francetvinfo.fr/titres.rss",
-                                          "http://www.france24.com/fr/actualites/rss",
-                                          "https://www.franceinter.fr/rss/a-la-une.xml",
-                                          "http://www.rfi.fr/general/rss",
-                                          "http://www.cnews.fr/rss/une",
-                                          "http://www.bfmtv.com/rss/info/flux-rss/flux-toutes-les-actualites/"
-                          });
-               
-               result.put(Category.SPORT,
-                               new String[] { "http://www.france24.com/fr/sports/rss" });
-               
-               result.put(Category.FRANCE,
-                                new String[] { "http://www.france24.com/fr/france/rss",
-                                               "http://www.rfi.fr/france/rss"});
-               
-               result.put(Category.EUROPE,
-                                new String[] { "http://www.france24.com/fr/europe/rss" });
-               
-               result.put(Category.ECO,
-                                new String[] { "http://www.france24.com/fr/economie/rss",
-                                               "http://www.rfi.fr/economie/rss" });
-               
-               result.put(Category.ESSONNE,
-                                new String[] { "https://www.essonneinfo.fr/feed/" });
-               
-               result.put(Category.TECHNOLOGIE,
-                                new String[] { "http://feeds.feedburner.com/lesnumeriques/news",
-                                               "http://www.zdnet.fr/feeds/rss/actualites/"});
-               
-               return result;
-       }
-       
-       private static List<Article> getArticles(Category cat) throws IllegalArgumentException, MalformedURLException, FeedException, IOException {
-               List<Article> articles;
-               String[] feeds;
-               Set<String> links;
-               
-               articles = new ArrayList<>();
-               
-               feeds = getFeeds().get(cat);
-               
-               if (feeds != null)
-                       for (String str: feeds)
-                               addArticles(cat, getSyndFeed(str), articles);
-               else
-                       LOG.severe("No feed for category " + cat);
-
-               links = new HashSet<>(articles.size());
-               for (Article a: articles) {
-                       if (links.contains(a.link))
-                               LOG.severe(a.link + "is not uniq");
-                       else
-                               links.add(a.link);
-               }
-               
-               articles.sort(new Comparator<Article> () {
-                        @Override
-                        public int compare(Article o1, Article o2) {
-                                return o2.publicationDate.compareTo(o1.publicationDate);
-                        }                      
-               });
-               
-               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, cat);
-               
-               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 {                            
-               System.out.println("pnews");
-               
-               for (Category cat: Category.values())
-                       writeHTMLFile(cat);
-               
-               System.out.println("done");
-       }
-}
\ No newline at end of file
diff --git a/src/main/scripts/pnews.sh b/src/main/scripts/pnews.sh
deleted file mode 100755 (executable)
index fbad98b..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/bash
-
-set -e
-
-SDIR=`dirname $0`
-
-java -classpath rome-1.8.0.jar -jar $SDIR/pnews-1.0.jar
diff --git a/style.css b/style.css
deleted file mode 100644 (file)
index cc79235..0000000
--- a/style.css
+++ /dev/null
@@ -1,74 +0,0 @@
-a {
-        text-decoration: none;
-        color: black;
-}
-
-body {
-        margin: 0 0 0 0;
-        padding: 1em 1em 1em 1em;
-        background-color: #eee;
-        font-family: sans-serif;
-        font-size: 100%;
-}
-
-nav {
-        font-size: 125%;
-        margin: 0 0 0 0;
-        padding: 0 0 0 0;
-}
-
-a.active {
-        text-decoration: none;
-        border-bottom: 4px solid black;
-}
-
-div {
-        margin: 0em 0em 0em 0em;
-        padding: 0 0 0 0;
-}
-
-div.article {
-        margin-bottom: 1em;
-}
-
-.article-info {
-        font-size: 80%;
-        color: #bbb;
-}
-
-img {
-        margin: 0em 1em 1em 0em;
-        padding: 0 0 0 0;
-        width: 8em;
-}
-
-p {
-        margin: 1em 1em 1em 1em;
-        padding: 0 0 0 0;
-}
-
-.left {
-        float: left;
-}
-
-h2 {
-        clear: left;
-        margin: 0 0 0 0;
-        padding: 0 0 0 0;
-}
-
-nav {
-        font-size: 120%;
-}
-
-nav ul {
-        list-style-type: none;
-        padding: 0 0 0 0;
-}
-
-nav ul li {
-        display: inline;
-        margin: 0em 1em 0 0;
-        padding: 0 0 0 0;
-        text-transform: uppercase;
-}