Browse Source

Ajout fonctionnalitée -debug

Martin Passard 7 years ago
parent
commit
27252afdad
2 changed files with 28 additions and 3 deletions
  1. 11 1
      src/data/ISPDAO.java
  2. 17 2
      src/main/Main.java

+ 11 - 1
src/data/ISPDAO.java

@@ -20,6 +20,8 @@ import javax.net.ssl.HttpsURLConnection;
 import org.json.JSONException;
 import org.json.JSONException;
 import org.json.JSONObject;
 import org.json.JSONObject;
 
 
+import main.Main;
+
 public class ISPDAO {
 public class ISPDAO {
 
 
 	/**
 	/**
@@ -127,7 +129,10 @@ public class ISPDAO {
 	public ISP getISP(int number) {
 	public ISP getISP(int number) {
 		String json = executeGet(dbAdress+number+'/');
 		String json = executeGet(dbAdress+number+'/');
 		if(json != null) {
 		if(json != null) {
+			if(Main.isDebug()) {
+				System.out.println("JSON du FAI "+number);
 		System.out.println(json);
 		System.out.println(json);
+			}
 		JSONObject jsonObj = new JSONObject(json);
 		JSONObject jsonObj = new JSONObject(json);
 		String name = getName(jsonObj);
 		String name = getName(jsonObj);
 		int id = getId(jsonObj);
 		int id = getId(jsonObj);
@@ -137,8 +142,13 @@ public class ISPDAO {
 		String last_update = getDateUpdated(jsonObj);
 		String last_update = getDateUpdated(jsonObj);
 		ISP isp = new ISP(name, id, member, date_added, last_update, ispData);
 		ISP isp = new ISP(name, id, member, date_added, last_update, ispData);
 		return isp;
 		return isp;
+		}else {
+			if(Main.isDebug()) {
+				System.out.println("Pas de JSON pour le FAI "+number);
+			}
+			
+			return null;
 		}
 		}
-		return null;
 
 
 	}
 	}
 	/**
 	/**

+ 17 - 2
src/main/Main.java

@@ -10,16 +10,27 @@ public class Main {
 	public static final long TIMEOUT_BEFORE_RECONNECTING = 360;
 	public static final long TIMEOUT_BEFORE_RECONNECTING = 360;
 	public static final Cache cache = Cache.getInstance();
 	public static final Cache cache = Cache.getInstance();
 	public static int failures = 0;
 	public static int failures = 0;
-	
+	private static boolean DEBUG;
 	
 	
 	public static void main(String[] args) throws Exception {
 	public static void main(String[] args) throws Exception {
 		
 		
+		for(int i=0;i<args.length;i++) {
+			if(args[i].equals("-debug")) {
+				DEBUG = true;
+			}
+			DEBUG = false;
+		}
+		
 		try {
 		try {
         // Now start our bot up.
         // Now start our bot up.
         Bot bot = new Bot();
         Bot bot = new Bot();
         
         
+        if(isDebug()) {
         // Enable debugging output.
         // Enable debugging output.
-        bot.setVerbose(true);
+        	bot.setVerbose(true);
+        }else {
+        	bot.setVerbose(false);
+        }
         
         
         // Connect to the IRC server.
         // Connect to the IRC server.
         bot.connect(SERVER,PORT);
         bot.connect(SERVER,PORT);
@@ -43,4 +54,8 @@ public class Main {
 		}
 		}
 	}
 	}
 
 
+	
+	public static boolean isDebug () {
+		return Main.DEBUG;
+	}
 }
 }