diff --git a/src/main/java/xyz/thastertyn/App.java b/src/main/java/xyz/thastertyn/App.java index 29eec7c..3dd77f6 100644 --- a/src/main/java/xyz/thastertyn/App.java +++ b/src/main/java/xyz/thastertyn/App.java @@ -1,6 +1,6 @@ package xyz.thastertyn; -import xyz.thastertyn.Window.MainWindow; +import xyz.thastertyn.ContentDisplay.MainWindow; /** * Hello world! diff --git a/src/main/java/xyz/thastertyn/ContentDisplay/Content/JecnaContent.java b/src/main/java/xyz/thastertyn/ContentDisplay/Content/JecnaContent.java new file mode 100644 index 0000000..b650424 --- /dev/null +++ b/src/main/java/xyz/thastertyn/ContentDisplay/Content/JecnaContent.java @@ -0,0 +1,17 @@ +package xyz.thastertyn.ContentDisplay.Content; + +import com.googlecode.lanterna.gui2.Panel; +import com.googlecode.lanterna.gui2.WindowBasedTextGUI; + +/** + * Wrapper to include all classes that deal with content in some way + */ +public abstract class JecnaContent { + + public abstract Panel getPanel(); + public abstract void download(String s); + public abstract boolean hasStarted(); + public abstract String getLabel(); + public abstract void specify(int y, int hy); + public abstract void getOptions(WindowBasedTextGUI textGUI); +} diff --git a/src/main/java/xyz/thastertyn/ContentDisplay/Content/Jidelna.java b/src/main/java/xyz/thastertyn/ContentDisplay/Content/Jidelna.java new file mode 100644 index 0000000..7368bb9 --- /dev/null +++ b/src/main/java/xyz/thastertyn/ContentDisplay/Content/Jidelna.java @@ -0,0 +1,5 @@ +package xyz.thastertyn.ContentDisplay.Content; + +public class Jidelna { + +} diff --git a/src/main/java/xyz/thastertyn/Window/Content/Rozvrh.java b/src/main/java/xyz/thastertyn/ContentDisplay/Content/Rozvrh.java similarity index 74% rename from src/main/java/xyz/thastertyn/Window/Content/Rozvrh.java rename to src/main/java/xyz/thastertyn/ContentDisplay/Content/Rozvrh.java index d530078..1419745 100644 --- a/src/main/java/xyz/thastertyn/Window/Content/Rozvrh.java +++ b/src/main/java/xyz/thastertyn/ContentDisplay/Content/Rozvrh.java @@ -1,10 +1,11 @@ -package xyz.thastertyn.Window.Content; +package xyz.thastertyn.ContentDisplay.Content; import java.io.IOException; import java.net.UnknownHostException; import com.googlecode.lanterna.gui2.Label; import com.googlecode.lanterna.gui2.Panel; +import com.googlecode.lanterna.gui2.WindowBasedTextGUI; import com.googlecode.lanterna.gui2.table.Table; public class Rozvrh extends JecnaContent { @@ -13,7 +14,7 @@ public class Rozvrh extends JecnaContent { private boolean hasStarted = false; - private xyz.thastertyn.Jecna.Rozvrh rozvrh = new xyz.thastertyn.Jecna.Rozvrh(); + private xyz.thastertyn.JecnaParse.Rozvrh rozvrh = new xyz.thastertyn.JecnaParse.Rozvrh(); private String[] labels = {"Den", "7:30-8:15", "8:25-9:10", "9:20-10:05", "10:20-11:05", "11:15-12:00", "12:10-12:55", "13:05-13:50", "14:00-14:45", "14:55-15:40", "15:50-16:35"}; //private String[] labels = {"Den", "1.", "2.", "3.", "4.", "5.", "6.", "7.", "8.", "9.", "10."}; @@ -70,4 +71,16 @@ public class Rozvrh extends JecnaContent { { return "Rozvrh"; } + + @Override + public void specify(int y, int hy) { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'specify'"); + } + + @Override + public void getOptions(WindowBasedTextGUI textGUI) { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'getOptions'"); + } } diff --git a/src/main/java/xyz/thastertyn/ContentDisplay/Content/Sdeleni.java b/src/main/java/xyz/thastertyn/ContentDisplay/Content/Sdeleni.java new file mode 100644 index 0000000..4e06603 --- /dev/null +++ b/src/main/java/xyz/thastertyn/ContentDisplay/Content/Sdeleni.java @@ -0,0 +1,90 @@ +package xyz.thastertyn.ContentDisplay.Content; + + +import java.io.IOException; +import java.net.UnknownHostException; +import java.util.ArrayList; + +import com.googlecode.lanterna.gui2.GridLayout; +import com.googlecode.lanterna.gui2.Label; +import com.googlecode.lanterna.gui2.Panel; +import com.googlecode.lanterna.gui2.WindowBasedTextGUI; + +import xyz.thastertyn.Tuple.Pair; + +public class Sdeleni extends JecnaContent { + + private Panel sdeleniPanel = new Panel(); + + private boolean hasStarted = false; + + private xyz.thastertyn.JecnaParse.Sdeleni sdeleni = new xyz.thastertyn.JecnaParse.Sdeleni(); + + @Override + public void download(String JsessionId) + { + if(!hasStarted) + { + try{ + + sdeleniPanel.setLayoutManager(new GridLayout(1) + .setLeftMarginSize(1) + .setRightMarginSize(1)); + + sdeleni.downloadSdeleni(JsessionId); + + ArrayList> sdeleniList = sdeleni.getSdeleni(); + + for(Pair p : sdeleniList) + { + String label = ""; + + if(p.getValue1()) + { + label += "✅"; + }else{ + label += "❌"; + } + + label += " " + p.getValue0(); + + sdeleniPanel.addComponent(new Label(label)); + } + hasStarted = true; + }catch(UnknownHostException e) + { + + }catch(IOException e) + { + + } + } + } + + @Override + public String getLabel() { + return "Sdeleni"; + } + + @Override + public Panel getPanel() { + return sdeleniPanel; + } + + @Override + public boolean hasStarted() { + return hasStarted; + } + + @Override + public void specify(int y, int hy) { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'specify'"); + } + + @Override + public void getOptions(WindowBasedTextGUI textGUI) { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'getOptions'"); + } +} diff --git a/src/main/java/xyz/thastertyn/Window/Content/Znamky.java b/src/main/java/xyz/thastertyn/ContentDisplay/Content/Znamky.java similarity index 86% rename from src/main/java/xyz/thastertyn/Window/Content/Znamky.java rename to src/main/java/xyz/thastertyn/ContentDisplay/Content/Znamky.java index 9c8ee5c..25ab6ea 100644 --- a/src/main/java/xyz/thastertyn/Window/Content/Znamky.java +++ b/src/main/java/xyz/thastertyn/ContentDisplay/Content/Znamky.java @@ -1,22 +1,24 @@ -package xyz.thastertyn.Window.Content; +package xyz.thastertyn.ContentDisplay.Content; import java.io.IOException; import java.util.ArrayList; -import com.googlecode.lanterna.SGR; import com.googlecode.lanterna.TextColor; import com.googlecode.lanterna.graphics.SimpleTheme; import com.googlecode.lanterna.gui2.Direction; import com.googlecode.lanterna.gui2.Label; import com.googlecode.lanterna.gui2.LinearLayout; import com.googlecode.lanterna.gui2.Panel; +import com.googlecode.lanterna.gui2.WindowBasedTextGUI; +import com.googlecode.lanterna.gui2.dialogs.ActionListDialogBuilder; + import xyz.thastertyn.Tuple.Pair; public class Znamky extends JecnaContent { private Panel znamkyPanel = new Panel().setLayoutManager(new LinearLayout(Direction.HORIZONTAL)); - private xyz.thastertyn.Jecna.Znamky znamky = new xyz.thastertyn.Jecna.Znamky(); + private xyz.thastertyn.JecnaParse.Znamky znamky = new xyz.thastertyn.JecnaParse.Znamky(); private boolean hasStarted = false; @@ -130,4 +132,16 @@ public class Znamky extends JecnaContent { { return "Znamky"; } + + @Override + public void specify(int y, int hy) { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'specify'"); + } + + @Override + public void getOptions(WindowBasedTextGUI textGUI) { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'getOptions'"); + } } diff --git a/src/main/java/xyz/thastertyn/Window/Login.java b/src/main/java/xyz/thastertyn/ContentDisplay/CredentialsInput.java similarity index 74% rename from src/main/java/xyz/thastertyn/Window/Login.java rename to src/main/java/xyz/thastertyn/ContentDisplay/CredentialsInput.java index ed3dd78..7793052 100644 --- a/src/main/java/xyz/thastertyn/Window/Login.java +++ b/src/main/java/xyz/thastertyn/ContentDisplay/CredentialsInput.java @@ -1,11 +1,7 @@ -package xyz.thastertyn.Window; +package xyz.thastertyn.ContentDisplay; -import java.io.IOException; -import java.net.UnknownHostException; import java.util.Arrays; -import javax.security.auth.login.CredentialException; - import com.googlecode.lanterna.TerminalSize; import com.googlecode.lanterna.gui2.Button; import com.googlecode.lanterna.gui2.EmptySpace; @@ -21,16 +17,18 @@ import com.googlecode.lanterna.gui2.dialogs.DialogWindow; import com.googlecode.lanterna.gui2.dialogs.MessageDialog; import com.googlecode.lanterna.gui2.dialogs.MessageDialogButton; -public class Login extends DialogWindow { +import xyz.thastertyn.Tuple.Pair; + +public class CredentialsInput extends DialogWindow { private TextBox username; private TextBox password; private String user; private String pass; - private xyz.thastertyn.Jecna.Login login = new xyz.thastertyn.Jecna.Login(); + //private xyz.thastertyn.JecnaParse.Login login = new xyz.thastertyn.JecnaParse.Login(); - Login() + CredentialsInput() { super("Login"); this.user = null; @@ -126,39 +124,16 @@ public class Login extends DialogWindow { return; } - try - { - login.loginJecna(user, pass); - } catch (UnknownHostException e) { - MessageDialog.showMessageDialog(getTextGUI(), "No Internet connection", - "There seems to be no internet connection, reverting to cached data", MessageDialogButton.OK); - return; - } catch (CredentialException e) - { - MessageDialog.showMessageDialog(getTextGUI(), "Incorrect username or password", - "The username or password you entered is incorrect", MessageDialogButton.OK); - return; - } catch (IOException e) - { - MessageDialog.showMessageDialog(getTextGUI(), "There was an error", "Maybe try again and it will go away", - MessageDialogButton.OK); - return; - } - close(); } - public String getJessionId() { - return login.getJSESSIONID(); - } - public void onCancel() { close(); } @Override - public String[] showDialog(WindowBasedTextGUI textGUI) { + public Pair showDialog(WindowBasedTextGUI textGUI) { super.showDialog(textGUI); - return new String[] { user, pass }; + return new Pair(user, pass); } } diff --git a/src/main/java/xyz/thastertyn/ContentDisplay/LoginController.java b/src/main/java/xyz/thastertyn/ContentDisplay/LoginController.java new file mode 100644 index 0000000..35f7a6c --- /dev/null +++ b/src/main/java/xyz/thastertyn/ContentDisplay/LoginController.java @@ -0,0 +1,190 @@ +package xyz.thastertyn.ContentDisplay; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.net.UnknownHostException; + +import javax.security.auth.login.CredentialException; + +import com.googlecode.lanterna.gui2.WindowBasedTextGUI; +import com.googlecode.lanterna.gui2.dialogs.MessageDialog; +import com.googlecode.lanterna.gui2.dialogs.MessageDialogButton; + +import xyz.thastertyn.Tuple.Pair; + +public class LoginController { + + private xyz.thastertyn.JecnaParse.Login login = new xyz.thastertyn.JecnaParse.Login(); + private xyz.thastertyn.ContentDisplay.CredentialsInput dialog = new CredentialsInput(); + + private WindowBasedTextGUI textGUI = null; + + public LoginController(WindowBasedTextGUI textGUI) + { + this.textGUI = textGUI; + } + + public void login() + { + if(checkForCredentials()) // Credentials exist + if(loginUsingCredentials()) // They are accessible and can read them + return; + + + try + { + Pair data = dialog.showDialog(textGUI); // Failed to get credentials to log in, get them from user + login.loginJecna(data.getValue0(), data.getValue1()); + } catch (UnknownHostException e) { + MessageDialog.showMessageDialog(textGUI, "No Internet connection", + "There seems to be no internet connection, reverting to cached data", + MessageDialogButton.OK); + return; + } catch (CredentialException e) + { + MessageDialog.showMessageDialog(textGUI, "Incorrect username or password", + "The username or password you entered is incorrect", + MessageDialogButton.OK); + return; + } catch (IOException e) + { + MessageDialog.showMessageDialog(textGUI, "There was an error", + "Maybe try again and it will go away", + MessageDialogButton.OK); + return; + } + + } + + /** + * Zkontroluje zda jiz neexistuji ulozene udaje na systemu + * @return
    + *
  • {@code true} soubor existuje a neni prazdny
  • + *
  • {@code false} neexistuje, nebo je prazdny
  • + *
+ */ + private boolean checkForCredentials() + { + return false; + //File credentials = null; + + //if(System.getProperty("os.name").equals("Linux")) + //{ + // credentials = new File("~/.local/share/jecnak/credentials.json"); + + //}else if(System.getProperty("os.name").contains("Windows")) + //{ + // credentials = new File(System.getenv("APPDATA\\jecnak\\")); + //} + + //if(!credentials.exists() || credentials.length() == 0) + //{ + // return false; + //} + //return true; + } + + public boolean saveCredentials(String user, String pass) + { + File credentials; + + if(System.getProperty("os.name").equals("Linux")) + { + credentials = new File("~/.local/share/jecnak/credentials.json"); + + }else if(System.getProperty("os.name").contains("Windows")) + { + credentials = new File(System.getenv("APPDATA\\jecnak\\")); + }else{ + return false; + } + + try { + BufferedWriter writer = new BufferedWriter(new FileWriter(credentials)); + writer.append("username=" + user); + writer.append("password=" + pass); + + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + return false; + } + + return true; + } + + private boolean loginUsingCredentials() + { + File credentials; + + if(System.getProperty("os.name").equals("Linux")) + { + credentials = new File("~/.local/share/jecnak/credentials.json"); + + }else if(System.getProperty("os.name").contains("Windows")) + { + credentials = new File(System.getenv("APPDATA\\jecnak\\")); + }else{ + return false; + } + + if(!credentials.exists() || credentials.length() == 0) + { + return false; + } + + String user = ""; + String pass = ""; + + try { + BufferedReader reader = new BufferedReader(new FileReader(credentials)); + + String line = ""; + while((line = reader.readLine()) != null) + { + if(line.matches("^[a-z]\\=.*$")) + { + String key = line.split("=")[0]; + String value = line.split("=")[1]; + + switch(key) + { + case "username": + user = value; + break; + case "password": + pass = value; + break; + default: + continue; + } + }else{ + continue; + } + } + + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + return false; + } + + try { + login.loginJecna(user, pass); + } catch (CredentialException | IOException e) { + e.printStackTrace(); + return false; + } + + return true; + } + + public String getJSessesionId() + { + return login.getJSESSIONID(); + } +} diff --git a/src/main/java/xyz/thastertyn/Window/MainWindow.java b/src/main/java/xyz/thastertyn/ContentDisplay/MainWindow.java similarity index 86% rename from src/main/java/xyz/thastertyn/Window/MainWindow.java rename to src/main/java/xyz/thastertyn/ContentDisplay/MainWindow.java index 25347be..0fc95cc 100644 --- a/src/main/java/xyz/thastertyn/Window/MainWindow.java +++ b/src/main/java/xyz/thastertyn/ContentDisplay/MainWindow.java @@ -1,4 +1,4 @@ -package xyz.thastertyn.Window; +package xyz.thastertyn.ContentDisplay; import java.io.IOException; import java.util.Arrays; @@ -54,19 +54,20 @@ public class MainWindow { Panel tabs = new Panel() .setLayoutManager(new LinearLayout(Direction.HORIZONTAL)) .addComponent(new Label("Rozvrh").withBorder(Borders.singleLine())) - .addComponent(new Label("Znamky").withBorder(Borders.singleLine())); + .addComponent(new Label("Znamky").withBorder(Borders.singleLine())) + .addComponent(new Label("Sdeleni R.").withBorder(Borders.singleLine())); mainPanel.addComponent(tabs); - String title = "Jecnak"; + String title = "Jecnak"; Panel content = new Panel(); mainPanel.addComponent(content.withBorder(Borders.singleLine(title))); - Login login = new Login(); - login.showDialog(textGUI); + LoginController controller = new LoginController(textGUI); + controller.login(); - window.addWindowListener(new WindowSwitchListener(content, login.getJessionId(), tabs, title)); + window.addWindowListener(new WindowSwitchListener(content, controller.getJSessesionId(), tabs, title)); textGUI.addWindowAndWait(window); diff --git a/src/main/java/xyz/thastertyn/Window/WindowSwitchListener.java b/src/main/java/xyz/thastertyn/ContentDisplay/WindowSwitchListener.java similarity index 86% rename from src/main/java/xyz/thastertyn/Window/WindowSwitchListener.java rename to src/main/java/xyz/thastertyn/ContentDisplay/WindowSwitchListener.java index 8b618a4..d4873a9 100644 --- a/src/main/java/xyz/thastertyn/Window/WindowSwitchListener.java +++ b/src/main/java/xyz/thastertyn/ContentDisplay/WindowSwitchListener.java @@ -1,4 +1,4 @@ -package xyz.thastertyn.Window; +package xyz.thastertyn.ContentDisplay; import java.util.concurrent.atomic.AtomicBoolean; @@ -11,20 +11,21 @@ import com.googlecode.lanterna.gui2.WindowListener; import com.googlecode.lanterna.input.KeyStroke; import com.googlecode.lanterna.input.KeyType; -import xyz.thastertyn.Window.Content.JecnaContent; -import xyz.thastertyn.Window.Content.Rozvrh; -import xyz.thastertyn.Window.Content.Znamky; +import xyz.thastertyn.ContentDisplay.Content.JecnaContent; +import xyz.thastertyn.ContentDisplay.Content.Rozvrh; +import xyz.thastertyn.ContentDisplay.Content.Sdeleni; +import xyz.thastertyn.ContentDisplay.Content.Znamky; public class WindowSwitchListener implements WindowListener { WindowBasedTextGUI gui; - private JecnaContent[] contents = {new Rozvrh(), new Znamky()}; + private JecnaContent[] contents = {new Rozvrh(), new Znamky(), new Sdeleni()}; private String JsessionId; - Panel content; - Panel tabs; + private Panel content; + private Panel tabs; String title; diff --git a/src/main/java/xyz/thastertyn/Jecna/Jidelna.java b/src/main/java/xyz/thastertyn/Jecna/Jidelna.java deleted file mode 100644 index 48b4871..0000000 --- a/src/main/java/xyz/thastertyn/Jecna/Jidelna.java +++ /dev/null @@ -1,5 +0,0 @@ -package xyz.thastertyn.Jecna; - -public class Jidelna { - -} diff --git a/src/main/java/xyz/thastertyn/Jecna/Dochazka.java b/src/main/java/xyz/thastertyn/JecnaParse/Dochazka.java similarity index 94% rename from src/main/java/xyz/thastertyn/Jecna/Dochazka.java rename to src/main/java/xyz/thastertyn/JecnaParse/Dochazka.java index ab34da4..bd053e4 100644 --- a/src/main/java/xyz/thastertyn/Jecna/Dochazka.java +++ b/src/main/java/xyz/thastertyn/JecnaParse/Dochazka.java @@ -1,4 +1,4 @@ -package xyz.thastertyn.Jecna; +package xyz.thastertyn.JecnaParse; import java.io.IOException; import java.util.HashMap; diff --git a/src/main/java/xyz/thastertyn/Jecna/Downloader.java b/src/main/java/xyz/thastertyn/JecnaParse/Downloader.java similarity index 89% rename from src/main/java/xyz/thastertyn/Jecna/Downloader.java rename to src/main/java/xyz/thastertyn/JecnaParse/Downloader.java index dc3f1ae..87d8817 100644 --- a/src/main/java/xyz/thastertyn/Jecna/Downloader.java +++ b/src/main/java/xyz/thastertyn/JecnaParse/Downloader.java @@ -1,4 +1,4 @@ -package xyz.thastertyn.Jecna; +package xyz.thastertyn.JecnaParse; import org.jsoup.Connection; import org.jsoup.Jsoup; diff --git a/src/main/java/xyz/thastertyn/JecnaParse/Jidelna.java b/src/main/java/xyz/thastertyn/JecnaParse/Jidelna.java new file mode 100644 index 0000000..2600d8d --- /dev/null +++ b/src/main/java/xyz/thastertyn/JecnaParse/Jidelna.java @@ -0,0 +1,5 @@ +package xyz.thastertyn.JecnaParse; + +public class Jidelna { + +} diff --git a/src/main/java/xyz/thastertyn/Jecna/Login.java b/src/main/java/xyz/thastertyn/JecnaParse/Login.java similarity index 75% rename from src/main/java/xyz/thastertyn/Jecna/Login.java rename to src/main/java/xyz/thastertyn/JecnaParse/Login.java index 385301e..6f53880 100644 --- a/src/main/java/xyz/thastertyn/Jecna/Login.java +++ b/src/main/java/xyz/thastertyn/JecnaParse/Login.java @@ -1,6 +1,5 @@ -package xyz.thastertyn.Jecna; +package xyz.thastertyn.JecnaParse; -import java.io.File; import java.io.IOException; import java.net.UnknownHostException; @@ -19,51 +18,6 @@ public class Login { private long start; private long lastCheck; - /** - * Zkontroluje zda jiz neexistuji ulozene udaje na systemu - * @return
    - *
  • {@code true} soubor existuje a neni prazdny
  • - *
  • {@code false} neexistuje, nebo jsou prazdne
  • - *
- */ - public boolean checkForCredentials() - { - File credentials = null; - - if(System.getProperty("os.name").equals("Linux")) - { - credentials = new File("~/.local/share/jecnak/credentials.json"); - - }else if(System.getProperty("os.name").contains("Windows")) - { - credentials = new File(System.getenv("APPDATA\\jecnak\\")); - } - - if(!credentials.exists() || credentials.length() == 0) - { - return false; - } - return true; - } - - public void saveCredentials(String user, String pass) - { - File credentials = null; - - if(System.getProperty("os.name").equals("Linux")) - { - credentials = new File("~/.local/share/jecnak/credentials.json"); - - }else if(System.getProperty("os.name").contains("Windows")) - { - credentials = new File(System.getenv("APPDATA\\jecnak\\")); - } - - if(!credentials.exists()) - { - - } - } public String getJSESSIONID() { @@ -94,7 +48,6 @@ public class Login { Jsoup.connect("https://www.spsejecna.cz/user/login") .method(Connection.Method.POST) .header("Content-Type", "application/x-www-form-urlencoded") - //.header("Content-Length", "71") Adds 10 seconds to total request time .header("Origin", "https://www.spsejecna.cz") .header("Connection", "keep-alive") .cookie("JSESSIONID", Jsessionid) @@ -122,7 +75,7 @@ public class Login { lastCheck = start; } - public void loginJidelna() throws UnknownHostException, IOException + /*public void loginJidelna() throws UnknownHostException, IOException { //#region JSESSIONID Connection.Response jidelna = Jsoup.connect("https://objednavky.jidelnasokolska.cz/") @@ -165,5 +118,5 @@ public class Login { .method(Method.POST) .execute(); //#endregion - } + }*/ } diff --git a/src/main/java/xyz/thastertyn/Jecna/Rozvrh.java b/src/main/java/xyz/thastertyn/JecnaParse/Rozvrh.java similarity index 98% rename from src/main/java/xyz/thastertyn/Jecna/Rozvrh.java rename to src/main/java/xyz/thastertyn/JecnaParse/Rozvrh.java index 7f49c21..a5c53f6 100644 --- a/src/main/java/xyz/thastertyn/Jecna/Rozvrh.java +++ b/src/main/java/xyz/thastertyn/JecnaParse/Rozvrh.java @@ -1,4 +1,4 @@ -package xyz.thastertyn.Jecna; +package xyz.thastertyn.JecnaParse; import java.io.IOException; import java.net.UnknownHostException; diff --git a/src/main/java/xyz/thastertyn/JecnaParse/Sdeleni.java b/src/main/java/xyz/thastertyn/JecnaParse/Sdeleni.java new file mode 100644 index 0000000..1d3a0e6 --- /dev/null +++ b/src/main/java/xyz/thastertyn/JecnaParse/Sdeleni.java @@ -0,0 +1,48 @@ +package xyz.thastertyn.JecnaParse; + +import java.io.IOException; +import java.net.UnknownHostException; +import java.util.ArrayList; + +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; + +import xyz.thastertyn.Tuple.Pair; + +public class Sdeleni { + + ArrayList> sdeleniList = new ArrayList<>(); + + public void downloadSdeleni(final String JsessionId) throws UnknownHostException, IOException + { + Document sdeleniDoc = Downloader.download("https://www.spsejecna.cz/user-student/record-list", JsessionId).get(); + + Elements sdeleni = sdeleniDoc.select("ul.list li"); + + for(Element e : sdeleni) + { + boolean isPositive = false; + String label = ""; + + Elements spans = e.select("li").select("a.item").select("span"); + + isPositive = spans.get(0).hasClass("sprite-icon-tick-16"); + label = spans.get(1).text(); + + //if(!label.startsWith(" ")) + //{ + // label = " " + label; + //} + + //label = label.replaceAll("\\s+$", ""); + + sdeleniList.add(new Pair(label, isPositive)); + } + } + + public ArrayList> getSdeleni() + { + return sdeleniList; + } +} diff --git a/src/main/java/xyz/thastertyn/Jecna/Znamky.java b/src/main/java/xyz/thastertyn/JecnaParse/Znamky.java similarity index 80% rename from src/main/java/xyz/thastertyn/Jecna/Znamky.java rename to src/main/java/xyz/thastertyn/JecnaParse/Znamky.java index 3358bc3..1bfcc38 100644 --- a/src/main/java/xyz/thastertyn/Jecna/Znamky.java +++ b/src/main/java/xyz/thastertyn/JecnaParse/Znamky.java @@ -1,4 +1,4 @@ -package xyz.thastertyn.Jecna; +package xyz.thastertyn.JecnaParse; import java.io.IOException; import java.net.UnknownHostException; @@ -18,14 +18,17 @@ public class Znamky { private ArrayList>,Double>>> grades = new ArrayList<>(); - public void addGrade(int index, String subject, int grade, double weight) + // Integer znaci id roku, boolean jestli je jen prvni nebo i druhe pololeti + private ArrayList> options = new ArrayList<>(); + + private void addGrade(int index, String subject, int grade, double weight) { Pair znamka = new Pair<>(grade, weight); grades.get(index).getValue1().getValue0().add(znamka); } - public void addSubject(String subject) + private void addSubject(String subject) { Pair>, Double> p = new Pair<>(new ArrayList>(), 0.0); @@ -61,7 +64,7 @@ public class Znamky { { wasDownloaded = true; //String url = String.format("https://www.spsejecna.cz/score/student?schoolYearId=%d&schoolYearHalfId=%d", schoolYearId, schoolYearHalfId); - Document znamkyDoc = Downloader.download("https://www.spsejecna.cz/score/student?schoolYearId=14&schoolYearHalfId=21", Jsessionid).get(); + Document znamkyDoc = Downloader.download("https://www.spsejecna.cz/score/student", Jsessionid).get(); Elements rows = znamkyDoc.select("table.score").select("tr"); @@ -111,6 +114,23 @@ public class Znamky { grades.get(subj).getValue1().setValue1(getAverage(grades.get(subj).getValue1().getValue0())); subj++; } +/* + Elements roky = znamkyDoc.select("select[name=schoolYearId]"); + Elements pololetiSelect = znamkyDoc.select("select[name=schoolYearHalfId]"); + + for(Element e : roky) + { + boolean jeCelyRok = false; + + if(pololetiSelect.size() == 2) + { + jeCelyRok = true; + } + + int rok = Integer.parseInt(e.attr("value")); + + options.add(new Pair(rok, jeCelyRok)); + }*/ } public ArrayList>,Double>>> getGrades() @@ -118,6 +138,11 @@ public class Znamky { return grades; } + public ArrayList> getOptions() + { + return options; + } + @Override public String toString() { @@ -133,6 +158,5 @@ public class Znamky { }else{ return "Nothing was downloaded"; } - } } \ No newline at end of file diff --git a/src/main/java/xyz/thastertyn/Window/Content/JecnaContent.java b/src/main/java/xyz/thastertyn/Window/Content/JecnaContent.java deleted file mode 100644 index 7994830..0000000 --- a/src/main/java/xyz/thastertyn/Window/Content/JecnaContent.java +++ /dev/null @@ -1,39 +0,0 @@ -package xyz.thastertyn.Window.Content; - -import com.googlecode.lanterna.gui2.Panel; - -/** - * Wrapper to include all classes that deal with content in some way - */ -public class JecnaContent { - - public Panel getPanel() - { - return null; - } - - public void download(String s) - { - - } - - public boolean hasStarted() - { - return false; - } - - public String getLabel() - { - return ""; - } - - public void specify(int y, int hy) - { - - } - - public void getOptions() - { - - } -} diff --git a/src/main/java/xyz/thastertyn/Window/Content/Jidelna.java b/src/main/java/xyz/thastertyn/Window/Content/Jidelna.java deleted file mode 100644 index 62fb593..0000000 --- a/src/main/java/xyz/thastertyn/Window/Content/Jidelna.java +++ /dev/null @@ -1,5 +0,0 @@ -package xyz.thastertyn.Window.Content; - -public class Jidelna { - -} diff --git a/target/classes/xyz/thastertyn/App.class b/target/classes/xyz/thastertyn/App.class index 8fc5f3f..7c1dfc3 100644 Binary files a/target/classes/xyz/thastertyn/App.class and b/target/classes/xyz/thastertyn/App.class differ diff --git a/target/classes/xyz/thastertyn/ContentDisplay/Content/JecnaContent.class b/target/classes/xyz/thastertyn/ContentDisplay/Content/JecnaContent.class new file mode 100644 index 0000000..a28c243 Binary files /dev/null and b/target/classes/xyz/thastertyn/ContentDisplay/Content/JecnaContent.class differ diff --git a/target/classes/xyz/thastertyn/ContentDisplay/Content/Jidelna.class b/target/classes/xyz/thastertyn/ContentDisplay/Content/Jidelna.class new file mode 100644 index 0000000..b396fa7 Binary files /dev/null and b/target/classes/xyz/thastertyn/ContentDisplay/Content/Jidelna.class differ diff --git a/target/classes/xyz/thastertyn/ContentDisplay/Content/Rozvrh.class b/target/classes/xyz/thastertyn/ContentDisplay/Content/Rozvrh.class new file mode 100644 index 0000000..55943eb Binary files /dev/null and b/target/classes/xyz/thastertyn/ContentDisplay/Content/Rozvrh.class differ diff --git a/target/classes/xyz/thastertyn/ContentDisplay/Content/Sdeleni.class b/target/classes/xyz/thastertyn/ContentDisplay/Content/Sdeleni.class new file mode 100644 index 0000000..6f248fc Binary files /dev/null and b/target/classes/xyz/thastertyn/ContentDisplay/Content/Sdeleni.class differ diff --git a/target/classes/xyz/thastertyn/Window/Content/Znamky.class b/target/classes/xyz/thastertyn/ContentDisplay/Content/Znamky.class similarity index 73% rename from target/classes/xyz/thastertyn/Window/Content/Znamky.class rename to target/classes/xyz/thastertyn/ContentDisplay/Content/Znamky.class index 1a537bb..dc5cd14 100644 Binary files a/target/classes/xyz/thastertyn/Window/Content/Znamky.class and b/target/classes/xyz/thastertyn/ContentDisplay/Content/Znamky.class differ diff --git a/target/classes/xyz/thastertyn/ContentDisplay/CredentialsInput.class b/target/classes/xyz/thastertyn/ContentDisplay/CredentialsInput.class new file mode 100644 index 0000000..7fcd5d0 Binary files /dev/null and b/target/classes/xyz/thastertyn/ContentDisplay/CredentialsInput.class differ diff --git a/target/classes/xyz/thastertyn/ContentDisplay/LoginController.class b/target/classes/xyz/thastertyn/ContentDisplay/LoginController.class new file mode 100644 index 0000000..b521cd9 Binary files /dev/null and b/target/classes/xyz/thastertyn/ContentDisplay/LoginController.class differ diff --git a/target/classes/xyz/thastertyn/Window/MainWindow.class b/target/classes/xyz/thastertyn/ContentDisplay/MainWindow.class similarity index 55% rename from target/classes/xyz/thastertyn/Window/MainWindow.class rename to target/classes/xyz/thastertyn/ContentDisplay/MainWindow.class index 87414dc..cec5373 100644 Binary files a/target/classes/xyz/thastertyn/Window/MainWindow.class and b/target/classes/xyz/thastertyn/ContentDisplay/MainWindow.class differ diff --git a/target/classes/xyz/thastertyn/ContentDisplay/WindowSwitchListener.class b/target/classes/xyz/thastertyn/ContentDisplay/WindowSwitchListener.class new file mode 100644 index 0000000..5e06dfc Binary files /dev/null and b/target/classes/xyz/thastertyn/ContentDisplay/WindowSwitchListener.class differ diff --git a/target/classes/xyz/thastertyn/Jecna/Jidelna.class b/target/classes/xyz/thastertyn/Jecna/Jidelna.class deleted file mode 100644 index b7f1869..0000000 Binary files a/target/classes/xyz/thastertyn/Jecna/Jidelna.class and /dev/null differ diff --git a/target/classes/xyz/thastertyn/Jecna/Login.class b/target/classes/xyz/thastertyn/Jecna/Login.class deleted file mode 100644 index 572fe36..0000000 Binary files a/target/classes/xyz/thastertyn/Jecna/Login.class and /dev/null differ diff --git a/target/classes/xyz/thastertyn/Jecna/Znamky.class b/target/classes/xyz/thastertyn/Jecna/Znamky.class deleted file mode 100644 index 9dc5e09..0000000 Binary files a/target/classes/xyz/thastertyn/Jecna/Znamky.class and /dev/null differ diff --git a/target/classes/xyz/thastertyn/Jecna/Dochazka.class b/target/classes/xyz/thastertyn/JecnaParse/Dochazka.class similarity index 65% rename from target/classes/xyz/thastertyn/Jecna/Dochazka.class rename to target/classes/xyz/thastertyn/JecnaParse/Dochazka.class index 42f6c0e..1be59ec 100644 Binary files a/target/classes/xyz/thastertyn/Jecna/Dochazka.class and b/target/classes/xyz/thastertyn/JecnaParse/Dochazka.class differ diff --git a/target/classes/xyz/thastertyn/Jecna/Downloader.class b/target/classes/xyz/thastertyn/JecnaParse/Downloader.class similarity index 64% rename from target/classes/xyz/thastertyn/Jecna/Downloader.class rename to target/classes/xyz/thastertyn/JecnaParse/Downloader.class index b6a040f..1135a57 100644 Binary files a/target/classes/xyz/thastertyn/Jecna/Downloader.class and b/target/classes/xyz/thastertyn/JecnaParse/Downloader.class differ diff --git a/target/classes/xyz/thastertyn/JecnaParse/Jidelna.class b/target/classes/xyz/thastertyn/JecnaParse/Jidelna.class new file mode 100644 index 0000000..365e7f2 Binary files /dev/null and b/target/classes/xyz/thastertyn/JecnaParse/Jidelna.class differ diff --git a/target/classes/xyz/thastertyn/JecnaParse/Login.class b/target/classes/xyz/thastertyn/JecnaParse/Login.class new file mode 100644 index 0000000..83f6c19 Binary files /dev/null and b/target/classes/xyz/thastertyn/JecnaParse/Login.class differ diff --git a/target/classes/xyz/thastertyn/Jecna/Rozvrh.class b/target/classes/xyz/thastertyn/JecnaParse/Rozvrh.class similarity index 89% rename from target/classes/xyz/thastertyn/Jecna/Rozvrh.class rename to target/classes/xyz/thastertyn/JecnaParse/Rozvrh.class index 2baaecf..ea187f9 100644 Binary files a/target/classes/xyz/thastertyn/Jecna/Rozvrh.class and b/target/classes/xyz/thastertyn/JecnaParse/Rozvrh.class differ diff --git a/target/classes/xyz/thastertyn/JecnaParse/Sdeleni.class b/target/classes/xyz/thastertyn/JecnaParse/Sdeleni.class new file mode 100644 index 0000000..22ea66e Binary files /dev/null and b/target/classes/xyz/thastertyn/JecnaParse/Sdeleni.class differ diff --git a/target/classes/xyz/thastertyn/JecnaParse/Znamky.class b/target/classes/xyz/thastertyn/JecnaParse/Znamky.class new file mode 100644 index 0000000..e8a058b Binary files /dev/null and b/target/classes/xyz/thastertyn/JecnaParse/Znamky.class differ diff --git a/target/classes/xyz/thastertyn/Window/Content/JecnaContent.class b/target/classes/xyz/thastertyn/Window/Content/JecnaContent.class deleted file mode 100644 index 0bf3b83..0000000 Binary files a/target/classes/xyz/thastertyn/Window/Content/JecnaContent.class and /dev/null differ diff --git a/target/classes/xyz/thastertyn/Window/Content/Jidelna.class b/target/classes/xyz/thastertyn/Window/Content/Jidelna.class deleted file mode 100644 index 2451488..0000000 Binary files a/target/classes/xyz/thastertyn/Window/Content/Jidelna.class and /dev/null differ diff --git a/target/classes/xyz/thastertyn/Window/Content/Rozvrh.class b/target/classes/xyz/thastertyn/Window/Content/Rozvrh.class deleted file mode 100644 index a60150f..0000000 Binary files a/target/classes/xyz/thastertyn/Window/Content/Rozvrh.class and /dev/null differ diff --git a/target/classes/xyz/thastertyn/Window/Login.class b/target/classes/xyz/thastertyn/Window/Login.class deleted file mode 100644 index b20da03..0000000 Binary files a/target/classes/xyz/thastertyn/Window/Login.class and /dev/null differ diff --git a/target/classes/xyz/thastertyn/Window/WindowSwitchListener.class b/target/classes/xyz/thastertyn/Window/WindowSwitchListener.class deleted file mode 100644 index c739a70..0000000 Binary files a/target/classes/xyz/thastertyn/Window/WindowSwitchListener.class and /dev/null differ