Browse Source

feat: Properties setter to RSSData

Martin Passard 7 years ago
parent
commit
bc45557eec
3 changed files with 35 additions and 4 deletions
  1. 5 2
      src/main/Main.java
  2. 9 2
      src/main/PropertiesSetter.java
  3. 21 0
      src/rss/RSSChecker.java

+ 5 - 2
src/main/Main.java

@@ -25,9 +25,12 @@ public class Main {
 			// Now start our bot up.
 			// Now start our bot up.
 			Bot bot = new Bot();
 			Bot bot = new Bot();
 			
 			
+			RSSChecker rcheck = new RSSChecker("https://planet.ffdn.org/atom.xml", bot);
+			
 			//Properties Setter
 			//Properties Setter
 			PropertiesSetter ps = new PropertiesSetter("../../ressources/config/config.properties");
 			PropertiesSetter ps = new PropertiesSetter("../../ressources/config/config.properties");
-			ps.setPropertiesOn(cr, bot);
+			
+			ps.setPropertiesOn(cr, bot,rcheck);
 
 
 			// Connect to the IRC server.
 			// Connect to the IRC server.
 			bot.connect(SERVER,PORT);
 			bot.connect(SERVER,PORT);
@@ -48,7 +51,7 @@ public class Main {
 			}
 			}
 			System.out.println("Debug? "+DEBUG);
 			System.out.println("Debug? "+DEBUG);
 			
 			
-			RSSChecker rcheck = new RSSChecker("https://planet.ffdn.org/atom.xml", bot);
+			
 			rcheck.start();
 			rcheck.start();
 			
 			
 		}catch(ConnectException ce) {
 		}catch(ConnectException ce) {

+ 9 - 2
src/main/PropertiesSetter.java

@@ -9,6 +9,7 @@ import java.util.Properties;
 import actions.Action;
 import actions.Action;
 import actions.Info;
 import actions.Info;
 import actions.Liste;
 import actions.Liste;
+import rss.RSSChecker;
 import verif_saisie.EntierPositifNonVide;
 import verif_saisie.EntierPositifNonVide;
 
 
 
 
@@ -26,7 +27,7 @@ public class PropertiesSetter {
 		f=configFile;
 		f=configFile;
 	}
 	}
 
 
-	public boolean setPropertiesOn(CacheReloader cr, Bot b) throws IOException,NumberFormatException {
+	public boolean setPropertiesOn(CacheReloader cr, Bot b, RSSChecker rssc) throws IOException,NumberFormatException {
 		System.out.println(here);
 		System.out.println(here);
 		System.out.println(here+File.separator+"ressources"+File.separator+"config"+File.separator+DEFAULT_PROPERTIES_FILE);
 		System.out.println(here+File.separator+"ressources"+File.separator+"config"+File.separator+DEFAULT_PROPERTIES_FILE);
 		FileReader defaultProperties = new FileReader(new File(here+File.separator+"ressources"+File.separator+"config"+File.separator+DEFAULT_PROPERTIES_FILE));
 		FileReader defaultProperties = new FileReader(new File(here+File.separator+"ressources"+File.separator+"config"+File.separator+DEFAULT_PROPERTIES_FILE));
@@ -81,8 +82,14 @@ public class PropertiesSetter {
 			Info.INFO_ALL = Boolean.parseBoolean(prop.getProperty("infoall"));
 			Info.INFO_ALL = Boolean.parseBoolean(prop.getProperty("infoall"));
 		}
 		}
 		
 		
+		setPropertiesOnRSS(prop, rssc);
 		
 		
-		
+		return true;
+	}
+	
+	public boolean setPropertiesOnRSS(Properties prop, RSSChecker rss) {
+		rss.setRssaddr(prop.getProperty("RSS_adress"));
+		rss.setTimeout(Integer.parseInt(prop.getProperty("RSS_new_article_check")));
 		return true;
 		return true;
 	}
 	}
 	
 	

+ 21 - 0
src/rss/RSSChecker.java

@@ -31,6 +31,10 @@ public class RSSChecker implements Runnable {
 	private Date lastarticle = new Date(); //last info
 	private Date lastarticle = new Date(); //last info
 	public static final SimpleDateFormat DATE_FORMATIN =  new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss'Z'");
 	public static final SimpleDateFormat DATE_FORMATIN =  new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss'Z'");
 	private Bot b;
 	private Bot b;
+	
+	public RSSChecker() {
+		this.rssaddr="";
+	}
 
 
 	public RSSChecker(String address, Bot b) {
 	public RSSChecker(String address, Bot b) {
 		this.rssaddr = address;
 		this.rssaddr = address;
@@ -90,6 +94,7 @@ public class RSSChecker implements Runnable {
 								b.sendMessageOnAllChannels("Nouveautée sur planet.ffdn.org:");
 								b.sendMessageOnAllChannels("Nouveautée sur planet.ffdn.org:");
 							}
 							}
 							afficheArticle(article);
 							afficheArticle(article);
+							lastarticle = date;
 						}
 						}
 						System.out.println(Main.DATE_FORMAT_OUT.format(date));
 						System.out.println(Main.DATE_FORMAT_OUT.format(date));
 					} catch (DOMException | ParseException e) {
 					} catch (DOMException | ParseException e) {
@@ -135,4 +140,20 @@ public class RSSChecker implements Runnable {
 
 
 
 
 	}
 	}
+
+	public String getRssaddr() {
+		return rssaddr;
+	}
+
+	public void setRssaddr(String rssaddr) {
+		this.rssaddr = rssaddr;
+	}
+
+	public long getTimeout() {
+		return timeout;
+	}
+
+	public void setTimeout(long timeout) {
+		this.timeout = timeout;
+	}
 }
 }