package nl.nickforall.squad.whatsappconvert;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class Main {

    public static DbManager database;

    public static void main(String[] args){
        File file = new File("logs.txt");
        System.out.println("Starting to convert!");

        String url = "jdbc:mysql://localhost:3306/squadstats";
        String user = "root";
        String password = "";

        database = new DbManager(password, user, url);

        try {
            BufferedReader br = new BufferedReader(new FileReader(file));
            String line;
            int i = 0;

            //stop after the first 5 loops because we're debugging
            while ((line = br.readLine()) != null && i < 5) {
                //do something useful this time
                i++;
                String[] msg = line.split(": ");
                if(msg.length > 2){
                    long timestamp = convertTimeString(msg[0]);
                    String name = msg[1];
                    String text = msg[2]; //TODO: merge all other strings in the array > 2

                    //debug lines
                    System.out.println(timestamp + " " + name + ": " + text);
                    database.addMessage(timestamp, text, name);
                } else if(msg.length == 2 && msg[1].contains("left")){
                    //log a leave thingy
                }
            }
        } catch(Exception ex) {
            if(ex instanceof FileNotFoundException){
                System.out.println("FATAL ERROR: could not find file " + file.getName());
            } else {
                System.out.println("FATAL ERROR: unknown fatal error occured, let's spam you with weird logs! ");
                ex.printStackTrace();
            }

        }

    }

    public static long convertTimeString(String time){
        try {
            SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yy hh:mm:ss");
            dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
            Date parsedDate = dateFormat.parse(time);
            return (parsedDate.getTime() / 1000L) ;
        } catch(Exception ex){
            ex.printStackTrace();
        }

        return 0;
    }
}

@@ -346,16 +346,80 @@
  args)%7B%0A
+        %0A        //defines the exported logs file from whatsapp%0A
         
@@ -504,16 +504,58 @@
 ert!%22);%0A
+        %0A        //mysql related variables
 %0A       
@@ -670,16 +670,68 @@
 d = %22%22;%0A
+        %0A        //opens an instance of the database
 %0A       
@@ -915,16 +915,28 @@
  i = 0;%0A
+            
 %0A       
@@ -946,60 +946,34 @@
   //
-stop after the first 5 loops because we're debugging
+while the next line exists
 %0A   
@@ -1022,17 +1022,8 @@
 null
- && i %3C 5
 ) %7B%0A
@@ -1042,145 +1042,277 @@
     
-//do something useful this time%0A                i++;%0A                String%5B%5D msg = line.split(%22: %22);%0A                if(msg.length %3E 2)%7B
+i++;%0A                %0A                //splits the time: name: message format to an array%0A                String%5B%5D msg = line.split(%22: %22);%0A                if(msg.length %3E 2)%7B%0A                    %0A                    //sets the array to variables so we can push it later
 %0A   
@@ -1618,16 +1618,59 @@
  text);%0A
+                    //push to the database%0A
         
@@ -2245,24 +2245,117 @@
    %7D%0A%0A    %7D%0A
+    %0A    /**%0A     * Converts a time as in the whatsapp logs to a unix timestamp%0A     */%0A     
 %0A    public 
@@ -2404,32 +2404,66 @@
 %7B%0A        try %7B%0A
+            //set the date format%0A
             Simp
@@ -2646,24 +2646,49 @@
 arse(time);%0A
+            //to seconds%0A
             

Add commenting in code