diff --git a/jecnak-tui.jar b/jecnak-tui.jar new file mode 100644 index 0000000..b6b25ca Binary files /dev/null and b/jecnak-tui.jar differ diff --git a/src/main/java/xyz/thastertyn/ContentDisplay/Content/JecnaContent.java b/src/main/java/xyz/thastertyn/ContentDisplay/Content/JecnaContent.java index bba5966..a416d6b 100644 --- a/src/main/java/xyz/thastertyn/ContentDisplay/Content/JecnaContent.java +++ b/src/main/java/xyz/thastertyn/ContentDisplay/Content/JecnaContent.java @@ -1,9 +1,8 @@ package xyz.thastertyn.ContentDisplay.Content; -import com.googlecode.lanterna.gui2.Border; -import com.googlecode.lanterna.gui2.Component; -import com.googlecode.lanterna.gui2.Panel; import com.googlecode.lanterna.gui2.WindowBasedTextGUI; +import com.googlecode.lanterna.gui2.Panel; +import com.googlecode.lanterna.gui2.Label; /** * Wrapper to include all classes that deal with content in some way @@ -11,9 +10,9 @@ import com.googlecode.lanterna.gui2.WindowBasedTextGUI; public abstract class JecnaContent { public abstract Panel getPanel(); - public abstract void download(final String JsessionId); + public abstract void download(); public abstract boolean hasStarted(); - public abstract Border getLabel(); + public abstract Label getLabel(); public abstract void specify(final int y, final int hy); public abstract void getOptions(final WindowBasedTextGUI textGUI); } diff --git a/src/main/java/xyz/thastertyn/ContentDisplay/Content/OmluvnyList.java b/src/main/java/xyz/thastertyn/ContentDisplay/Content/OmluvnyList.java index b0895b5..9987659 100644 --- a/src/main/java/xyz/thastertyn/ContentDisplay/Content/OmluvnyList.java +++ b/src/main/java/xyz/thastertyn/ContentDisplay/Content/OmluvnyList.java @@ -4,26 +4,24 @@ import java.io.IOException; import java.net.UnknownHostException; import java.util.ArrayList; -import com.googlecode.lanterna.gui2.Border; -import com.googlecode.lanterna.gui2.Borders; -import com.googlecode.lanterna.gui2.Component; import com.googlecode.lanterna.gui2.Label; import com.googlecode.lanterna.gui2.Panel; import com.googlecode.lanterna.gui2.WindowBasedTextGUI; -import xyz.thastertyn.Tuple.Pair; +import xyz.thastertyn.Tuples.Pair; public class OmluvnyList extends JecnaContent{ private Panel omluvnyPanel = new Panel(); + private Label borderLabel = new Label("Omluvny L."); private xyz.thastertyn.JecnaParse.OmluvnyList omluvnyList = new xyz.thastertyn.JecnaParse.OmluvnyList(); private boolean hasStarted = false; @Override - public void download(final String JsessionId) { + public void download() { try{ - omluvnyList.downloadOmluvnyList(JsessionId); + omluvnyList.downloadOmluvnyList(); ArrayList> a = omluvnyList.getData(); @@ -51,8 +49,8 @@ public class OmluvnyList extends JecnaContent{ } @Override - public Border getLabel() { - return new Label("Omluvny L.").withBorder(Borders.singleLine()); + public Label getLabel() { + return borderLabel; } @Override diff --git a/src/main/java/xyz/thastertyn/ContentDisplay/Content/Rozvrh.java b/src/main/java/xyz/thastertyn/ContentDisplay/Content/Rozvrh.java index 7493a89..14170e5 100644 --- a/src/main/java/xyz/thastertyn/ContentDisplay/Content/Rozvrh.java +++ b/src/main/java/xyz/thastertyn/ContentDisplay/Content/Rozvrh.java @@ -3,9 +3,6 @@ package xyz.thastertyn.ContentDisplay.Content; import java.io.IOException; import java.net.UnknownHostException; -import com.googlecode.lanterna.gui2.Border; -import com.googlecode.lanterna.gui2.Borders; -import com.googlecode.lanterna.gui2.Component; import com.googlecode.lanterna.gui2.Label; import com.googlecode.lanterna.gui2.Panel; import com.googlecode.lanterna.gui2.WindowBasedTextGUI; @@ -14,11 +11,11 @@ import com.googlecode.lanterna.gui2.table.Table; public class Rozvrh extends JecnaContent { private Panel rozvrhPanel = new Panel(); + private Label borderLabel = new Label("Rozvrh"); + private xyz.thastertyn.JecnaParse.Rozvrh rozvrh = new xyz.thastertyn.JecnaParse.Rozvrh(); private boolean hasStarted = false; - 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."}; @@ -27,10 +24,10 @@ public class Rozvrh extends JecnaContent { Table t = new Table<>(labels); @Override - public void download(String Jsessionid) + public void download() { try{ - rozvrh.downloadRozvrh(Jsessionid); + rozvrh.downloadRozvrh(); String[][] rozvrhArray = rozvrh.getRozvrh(); @@ -70,9 +67,9 @@ public class Rozvrh extends JecnaContent { } @Override - public Border getLabel() + public Label getLabel() { - return new Label("Rozvrh").withBorder(Borders.doubleLine()); + return borderLabel; } @Override diff --git a/src/main/java/xyz/thastertyn/ContentDisplay/Content/Sdeleni.java b/src/main/java/xyz/thastertyn/ContentDisplay/Content/Sdeleni.java index 3c366e7..b47e785 100644 --- a/src/main/java/xyz/thastertyn/ContentDisplay/Content/Sdeleni.java +++ b/src/main/java/xyz/thastertyn/ContentDisplay/Content/Sdeleni.java @@ -5,26 +5,25 @@ import java.io.IOException; import java.net.UnknownHostException; import java.util.ArrayList; -import com.googlecode.lanterna.gui2.Border; -import com.googlecode.lanterna.gui2.Borders; -import com.googlecode.lanterna.gui2.Component; 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; +import xyz.thastertyn.Tuples.Pair; public class Sdeleni extends JecnaContent { private Panel sdeleniPanel = new Panel(); - - private boolean hasStarted = false; + private Label borderLabel = new Label("Sdeleni R."); private xyz.thastertyn.JecnaParse.Sdeleni sdeleni = new xyz.thastertyn.JecnaParse.Sdeleni(); + private boolean hasStarted = false; + + @Override - public void download(String JsessionId) + public void download() { if(!hasStarted) { @@ -34,7 +33,7 @@ public class Sdeleni extends JecnaContent { .setLeftMarginSize(1) .setRightMarginSize(1)); - sdeleni.downloadSdeleni(JsessionId); + sdeleni.downloadSdeleni(); ArrayList> sdeleniList = sdeleni.getSdeleni(); @@ -65,8 +64,8 @@ public class Sdeleni extends JecnaContent { } @Override - public Border getLabel() { - return new Label("Sdeleni R.").withBorder(Borders.singleLine()); + public Label getLabel() { + return borderLabel; } @Override diff --git a/src/main/java/xyz/thastertyn/ContentDisplay/Content/Znamky.java b/src/main/java/xyz/thastertyn/ContentDisplay/Content/Znamky.java index cf28fe5..f8a6e3e 100644 --- a/src/main/java/xyz/thastertyn/ContentDisplay/Content/Znamky.java +++ b/src/main/java/xyz/thastertyn/ContentDisplay/Content/Znamky.java @@ -5,34 +5,54 @@ import java.util.ArrayList; import com.googlecode.lanterna.TextColor; import com.googlecode.lanterna.graphics.SimpleTheme; -import com.googlecode.lanterna.gui2.Border; -import com.googlecode.lanterna.gui2.Borders; -import com.googlecode.lanterna.gui2.Component; import com.googlecode.lanterna.gui2.Direction; +import com.googlecode.lanterna.gui2.GridLayout; 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 xyz.thastertyn.Tuple.Pair; +import xyz.thastertyn.Tuples.Pair; public class Znamky extends JecnaContent { - private Panel znamkyPanel = new Panel().setLayoutManager(new LinearLayout(Direction.HORIZONTAL)); - - private xyz.thastertyn.JecnaParse.Znamky znamky = new xyz.thastertyn.JecnaParse.Znamky(); + private Panel mainPanel = new Panel() + .setLayoutManager(new GridLayout(3)); + private Label borderLabel = new Label("Znamky"); + private xyz.thastertyn.JecnaParse.Znamky znamky = new xyz.thastertyn.JecnaParse.Znamky(); + private boolean hasStarted = false; @Override - public void download(String JsessionId) + public void download() { try{ - znamky.downloadZnamky(JsessionId); + znamky.downloadZnamky(); - Panel predmetyPanel = new Panel().setLayoutManager(new LinearLayout(Direction.VERTICAL)); - Panel znamkyP = new Panel().setLayoutManager(new LinearLayout(Direction.VERTICAL)); - Panel vyslPanel = new Panel().setLayoutManager(new LinearLayout(Direction.VERTICAL)); + Panel predmetyPanel = new Panel() + .setLayoutManager(new LinearLayout(Direction.VERTICAL)) + .setLayoutData(GridLayout.createLayoutData( + GridLayout.Alignment.BEGINNING, + GridLayout.Alignment.BEGINNING, + false, + false)); + + Panel znamkyPanel = new Panel() + .setLayoutManager(new LinearLayout(Direction.VERTICAL)) + .setLayoutData(GridLayout.createLayoutData( + GridLayout.Alignment.BEGINNING, + GridLayout.Alignment.BEGINNING, + false, + false)); + + Panel vyslednaZnamkaPanel = new Panel(). + setLayoutManager(new LinearLayout(Direction.VERTICAL)) + .setLayoutData(GridLayout.createLayoutData( + GridLayout.Alignment.END, + GridLayout.Alignment.BEGINNING, + true, + false)); ArrayList>,Double>>> grades = znamky.getGrades(); @@ -44,18 +64,16 @@ public class Znamky extends JecnaContent { for(Pair>,Double>> predmet : grades) { - predmetyPanel.addComponent(new Label(predmet.getValue0())); - Panel znamkyZPredmetu = new Panel().setLayoutManager(new LinearLayout(Direction.HORIZONTAL)); + Panel jednotliveZnamky = new Panel().setLayoutManager(new LinearLayout(Direction.HORIZONTAL)); if(predmet.getValue1().getValue0().isEmpty()) { - znamkyZPredmetu.addComponent(new Label("")); + jednotliveZnamky.addComponent(new Label("")); } for(Pair znamka : predmet.getValue1().getValue0()) { - // TODO pridat predmet.getValue0() ktery premeni znamky na jmeno predmetu jako funkci (not a bug, its a feature) Label znamkaLabel = new Label(znamka.getValue0() + ""); switch(znamka.getValue0()) { @@ -80,11 +98,9 @@ public class Znamky extends JecnaContent { break; } - znamkyZPredmetu.addComponent(znamkaLabel); + jednotliveZnamky.addComponent(znamkaLabel); } - znamkyP.addComponent(znamkyZPredmetu); - double prumer = predmet.getValue1().getValue1(); Label vysl = new Label(String.format("%.2f", prumer)); @@ -108,24 +124,26 @@ public class Znamky extends JecnaContent { vysl.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, nedostatecny)); } - vyslPanel.addComponent(vysl); + znamkyPanel.addComponent(jednotliveZnamky); + predmetyPanel.addComponent(new Label(predmet.getValue0())); + vyslednaZnamkaPanel.addComponent(vysl); } - znamkyPanel.addComponent(predmetyPanel); - znamkyPanel.addComponent(znamkyP); - znamkyPanel.addComponent(vyslPanel); + mainPanel.addComponent(predmetyPanel); + mainPanel.addComponent(znamkyPanel); + mainPanel.addComponent(vyslednaZnamkaPanel); hasStarted = true; }catch(IOException e) { - znamkyPanel.addComponent(new Label("An error has occured")); + mainPanel.addComponent(new Label("An error has occured")); } } @Override public Panel getPanel() { - return znamkyPanel; + return mainPanel; } @Override @@ -135,9 +153,9 @@ public class Znamky extends JecnaContent { } @Override - public Border getLabel() + public Label getLabel() { - return new Label("Znamky").withBorder(Borders.singleLine()); + return borderLabel; } @Override diff --git a/src/main/java/xyz/thastertyn/ContentDisplay/CredentialsInput.java b/src/main/java/xyz/thastertyn/ContentDisplay/CredentialsInput.java index 7793052..5d2e75d 100644 --- a/src/main/java/xyz/thastertyn/ContentDisplay/CredentialsInput.java +++ b/src/main/java/xyz/thastertyn/ContentDisplay/CredentialsInput.java @@ -4,6 +4,7 @@ import java.util.Arrays; import com.googlecode.lanterna.TerminalSize; import com.googlecode.lanterna.gui2.Button; +import com.googlecode.lanterna.gui2.CheckBox; import com.googlecode.lanterna.gui2.EmptySpace; import com.googlecode.lanterna.gui2.GridLayout; import com.googlecode.lanterna.gui2.Label; @@ -17,7 +18,7 @@ import com.googlecode.lanterna.gui2.dialogs.DialogWindow; import com.googlecode.lanterna.gui2.dialogs.MessageDialog; import com.googlecode.lanterna.gui2.dialogs.MessageDialogButton; -import xyz.thastertyn.Tuple.Pair; +import xyz.thastertyn.Tuples.Triplet; public class CredentialsInput extends DialogWindow { @@ -26,8 +27,8 @@ public class CredentialsInput extends DialogWindow { private String user; private String pass; - //private xyz.thastertyn.JecnaParse.Login login = new xyz.thastertyn.JecnaParse.Login(); - + private CheckBox remember; + CredentialsInput() { super("Login"); @@ -35,6 +36,7 @@ public class CredentialsInput extends DialogWindow { this.pass = null; this.username = new TextBox(); this.password = new TextBox().setMask('*'); + this.remember = new CheckBox(); Panel buttonPanel = new Panel(); buttonPanel @@ -99,6 +101,18 @@ public class CredentialsInput extends DialogWindow { .addComponent(password) .addTo(mainPanel); + Panel rememberPanel = new Panel() + .setLayoutManager(new GridLayout(3)) + .setLayoutData(GridLayout.createLayoutData( + GridLayout.Alignment.FILL, + Alignment.CENTER, + true, + false)); + + rememberPanel.addComponent(new Label("Rembember?")) + .addComponent(remember) + .addTo(mainPanel); + mainPanel.addComponent(new EmptySpace(TerminalSize.ONE)); buttonPanel.setLayoutData( @@ -132,8 +146,8 @@ public class CredentialsInput extends DialogWindow { } @Override - public Pair showDialog(WindowBasedTextGUI textGUI) { + public Triplet showDialog(WindowBasedTextGUI textGUI) { super.showDialog(textGUI); - return new Pair(user, pass); + return new Triplet(user, pass, remember.isChecked()); } } diff --git a/src/main/java/xyz/thastertyn/ContentDisplay/LoginController.java b/src/main/java/xyz/thastertyn/ContentDisplay/LoginController.java index 35f7a6c..9128738 100644 --- a/src/main/java/xyz/thastertyn/ContentDisplay/LoginController.java +++ b/src/main/java/xyz/thastertyn/ContentDisplay/LoginController.java @@ -14,7 +14,7 @@ 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; +import xyz.thastertyn.Tuples.Triplet; public class LoginController { @@ -31,13 +31,16 @@ public class LoginController { 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 + Triplet 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", @@ -54,10 +57,9 @@ public class LoginController { { MessageDialog.showMessageDialog(textGUI, "There was an error", "Maybe try again and it will go away", - MessageDialogButton.OK); + MessageDialogButton.Retry); return; } - } /** @@ -182,9 +184,4 @@ public class LoginController { return true; } - - public String getJSessesionId() - { - return login.getJSESSIONID(); - } } diff --git a/src/main/java/xyz/thastertyn/ContentDisplay/MainWindow.java b/src/main/java/xyz/thastertyn/ContentDisplay/MainWindow.java index bde7ae2..cd7ead7 100644 --- a/src/main/java/xyz/thastertyn/ContentDisplay/MainWindow.java +++ b/src/main/java/xyz/thastertyn/ContentDisplay/MainWindow.java @@ -9,7 +9,6 @@ import com.googlecode.lanterna.gui2.Borders; import com.googlecode.lanterna.gui2.DefaultWindowManager; import com.googlecode.lanterna.gui2.Direction; import com.googlecode.lanterna.gui2.EmptySpace; -import com.googlecode.lanterna.gui2.Label; import com.googlecode.lanterna.gui2.LinearLayout; import com.googlecode.lanterna.gui2.MultiWindowTextGUI; import com.googlecode.lanterna.gui2.Panel; @@ -50,11 +49,6 @@ public class MainWindow { mainPanel.setLayoutManager(new LinearLayout(Direction.VERTICAL)); window.setComponent(mainPanel); - - Panel tabs = new Panel() - .setLayoutManager(new LinearLayout(Direction.HORIZONTAL)); - - mainPanel.addComponent(tabs); String title = "Jecnak"; @@ -64,7 +58,7 @@ public class MainWindow { LoginController controller = new LoginController(textGUI); controller.login(); - window.addWindowListener(new WindowSwitchListener(content, controller.getJSessesionId(), tabs, title)); + window.addWindowListener(new WindowSwitchListener(content, title)); textGUI.addWindowAndWait(window); diff --git a/src/main/java/xyz/thastertyn/ContentDisplay/WindowSwitchListener.java b/src/main/java/xyz/thastertyn/ContentDisplay/WindowSwitchListener.java index 320f4fa..f581ca6 100644 --- a/src/main/java/xyz/thastertyn/ContentDisplay/WindowSwitchListener.java +++ b/src/main/java/xyz/thastertyn/ContentDisplay/WindowSwitchListener.java @@ -4,12 +4,12 @@ import java.util.concurrent.atomic.AtomicBoolean; import com.googlecode.lanterna.TerminalPosition; import com.googlecode.lanterna.TerminalSize; -import com.googlecode.lanterna.gui2.Border; import com.googlecode.lanterna.gui2.Borders; +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.Window; -import com.googlecode.lanterna.gui2.WindowBasedTextGUI; import com.googlecode.lanterna.gui2.WindowListener; import com.googlecode.lanterna.input.KeyStroke; import com.googlecode.lanterna.input.KeyType; @@ -22,38 +22,32 @@ import xyz.thastertyn.ContentDisplay.Content.Znamky; public class WindowSwitchListener implements WindowListener { - WindowBasedTextGUI gui; - private JecnaContent[] contents = {new Rozvrh(), new Znamky(), new Sdeleni(), new OmluvnyList()}; - private Border[] tabs = new Border[contents.length]; + private Label[] tabs = new Label[contents.length]; - private Panel tabsPanel; - private Panel content; + private Panel tabsPanel = new Panel().setLayoutManager(new LinearLayout(Direction.HORIZONTAL)); + private Panel content = new Panel(); - private String JsessionId; + private Panel errorPanel = new Panel().addComponent(new Label("Something went wrong")); - int current = 0; + int current = contents.length - 1; - public WindowSwitchListener(Panel holder, String JsessionId, Panel tabs, String title) + public WindowSwitchListener(Panel holder, String title) { - this.content = holder; - this.tabsPanel = tabs; - this.JsessionId = JsessionId; - addTabs(); - defaultPanel(); - } - - private void defaultPanel() - { - contents[0].download(JsessionId); - content.removeAllComponents(); - content.addComponent(contents[0].getPanel()); + holder.addComponent(tabsPanel); + holder.addComponent(content.withBorder(Borders.singleLine())); + + for(int i = 0; i < contents.length; i++) + { + this.tabs[i] = contents[i].getLabel(); + tabsPanel.addComponent(this.tabs[i]); + } + + next(); } - public void next() + private void next() { - // tabs.getChildrenList().get(current).withBorder(Borders.singleLine()); - if(current + 1 == contents.length) { current = 0; @@ -63,39 +57,37 @@ public class WindowSwitchListener implements WindowListener { if(!contents[current].hasStarted()) { - contents[current].download(JsessionId); + contents[current].download(); } - // tabs[current].getComponent().withBorder(Borders.doubleLine()); - content.removeAllComponents(); - content.addComponent(contents[current].getPanel()); + tabsPanel.removeAllComponents(); - } - - public void previous() - { - if(current - 1 == -1) + if(contents[current].hasStarted()) { - current = contents.length - 1; + int tabColumns = tabsPanel.getSize().getColumns(); + + if(contents[current].getPanel().getSize().getColumns() < tabColumns) + { + content.addComponent( + contents[current].getPanel().setPreferredSize(new TerminalSize(tabColumns, + contents[current].getPanel().getPreferredSize().getRows()))); + + }else{ + content.addComponent(contents[current].getPanel()); + } }else{ - current--; + content.addComponent(errorPanel); } - if(!contents[current].hasStarted()) + for(int i = 0; i < tabs.length; i++) { - contents[current].download(JsessionId); - } - content.removeAllComponents(); - content.addComponent(contents[current].getPanel()); - } - - private void addTabs() - { - for(int i = 0; i < contents.length; i++) - { - tabs[i] = contents[i].getLabel(); - tabsPanel.addComponent(tabs[i]); + if(i == current) + { + tabsPanel.addComponent(tabs[i].withBorder(Borders.doubleLine())); + }else{ + tabsPanel.addComponent(tabs[i].withBorder(Borders.singleLine())); + } } } @@ -106,12 +98,7 @@ public class WindowSwitchListener implements WindowListener { switch(type) { case Tab: - if(!keyStroke.isShiftDown()) - { - next(); - }else{ - previous(); - } + next(); break; default: break; diff --git a/src/main/java/xyz/thastertyn/JecnaParse/Dochazka.java b/src/main/java/xyz/thastertyn/JecnaParse/Dochazka.java deleted file mode 100644 index bd053e4..0000000 --- a/src/main/java/xyz/thastertyn/JecnaParse/Dochazka.java +++ /dev/null @@ -1,32 +0,0 @@ -package xyz.thastertyn.JecnaParse; - -import java.io.IOException; -import java.util.HashMap; - -import org.jsoup.Jsoup; -import org.jsoup.nodes.Document; - -import xyz.thastertyn.Tuple.Pair; - -public class Dochazka { - - private HashMap> absence = new HashMap<>(); - - public byte downloadAbsence(String JSESSIOND) - { - Document absenceDoc; - - try { - // absence-list - absenceDoc = Jsoup.connect("https://www.spsejecna.cz" + "/absence/passing-student") - .cookie("JSESSIOND", JSESSIOND) - .cookie("role", "student") - .header("Connection", "keep-alive") - .get(); - } catch (IOException e) { - e.printStackTrace(); - } - - return 0; - } -} diff --git a/src/main/java/xyz/thastertyn/JecnaParse/Downloader.java b/src/main/java/xyz/thastertyn/JecnaParse/Downloader.java index 87d8817..5839e06 100644 --- a/src/main/java/xyz/thastertyn/JecnaParse/Downloader.java +++ b/src/main/java/xyz/thastertyn/JecnaParse/Downloader.java @@ -5,11 +5,19 @@ import org.jsoup.Jsoup; public class Downloader { - public static Connection download(String url, String Jsessionid) + private static String JsessionId; + + public static Connection download(String url) { - return Jsoup.connect(url) + Connection c = Jsoup.connect(url) .header("Connection", "keep-alive") .cookie("role", "student") - .cookie("JSESSIONID", Jsessionid); + .cookie("JSESSIONID", JsessionId); + return c; + } + + public static void setJSessionId(String JsId) + { + JsessionId = JsId; } } diff --git a/src/main/java/xyz/thastertyn/JecnaParse/Login.java b/src/main/java/xyz/thastertyn/JecnaParse/Login.java index 6f53880..ff0a2ff 100644 --- a/src/main/java/xyz/thastertyn/JecnaParse/Login.java +++ b/src/main/java/xyz/thastertyn/JecnaParse/Login.java @@ -18,12 +18,6 @@ public class Login { private long start; private long lastCheck; - - public String getJSESSIONID() - { - return Jsessionid; - } - public void loginJecna(String user, String pass) throws UnknownHostException, IOException, CredentialException { //#region JSESSIONID @@ -33,6 +27,7 @@ public class Login { .execute(); Jsessionid = response.cookie("JSESSIONID"); + Downloader.setJSessionId(Jsessionid); //#endregion //#region Token3 diff --git a/src/main/java/xyz/thastertyn/JecnaParse/OmluvnyList.java b/src/main/java/xyz/thastertyn/JecnaParse/OmluvnyList.java index f79199e..b558dbc 100644 --- a/src/main/java/xyz/thastertyn/JecnaParse/OmluvnyList.java +++ b/src/main/java/xyz/thastertyn/JecnaParse/OmluvnyList.java @@ -8,7 +8,7 @@ import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; -import xyz.thastertyn.Tuple.Pair; +import xyz.thastertyn.Tuples.Pair; public class OmluvnyList { @@ -16,9 +16,9 @@ public class OmluvnyList { private boolean wasDownloaded = false; - public void downloadOmluvnyList(final String JsessionId) throws UnknownHostException, IOException + public void downloadOmluvnyList() throws UnknownHostException, IOException { - Document doc = Downloader.download("https://www.spsejecna.cz/absence/student", JsessionId).get(); + Document doc = Downloader.download("https://www.spsejecna.cz/absence/student").get(); Elements omluv = doc.select("table.absence-list").select("tr"); diff --git a/src/main/java/xyz/thastertyn/JecnaParse/Rozvrh.java b/src/main/java/xyz/thastertyn/JecnaParse/Rozvrh.java index a5c53f6..20cd777 100644 --- a/src/main/java/xyz/thastertyn/JecnaParse/Rozvrh.java +++ b/src/main/java/xyz/thastertyn/JecnaParse/Rozvrh.java @@ -50,9 +50,9 @@ public class Rozvrh { * @throws UnknownHostException kdyz neni pripojeni k internetu * @throws IOException ostatni exceptiony nejsou dulezite, tak jsou zahrnuty v jednom */ - public void downloadRozvrh(final String Jsessionid) throws UnknownHostException, IOException + public void downloadRozvrh() throws UnknownHostException, IOException { - Document rozvrhDoc = Downloader.download("https://www.spsejecna.cz" + "/timetable/class", Jsessionid).get(); + Document rozvrhDoc = Downloader.download("https://www.spsejecna.cz" + "/timetable/class").get(); Elements rozvrhTable = rozvrhDoc.select("table.timetable").select("tr"); Elements[] rozvrhDny = new Elements[rozvrhTable.size()]; diff --git a/src/main/java/xyz/thastertyn/JecnaParse/Sdeleni.java b/src/main/java/xyz/thastertyn/JecnaParse/Sdeleni.java index 1d3a0e6..340e237 100644 --- a/src/main/java/xyz/thastertyn/JecnaParse/Sdeleni.java +++ b/src/main/java/xyz/thastertyn/JecnaParse/Sdeleni.java @@ -8,15 +8,15 @@ import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; -import xyz.thastertyn.Tuple.Pair; +import xyz.thastertyn.Tuples.Pair; public class Sdeleni { ArrayList> sdeleniList = new ArrayList<>(); - public void downloadSdeleni(final String JsessionId) throws UnknownHostException, IOException + public void downloadSdeleni() throws UnknownHostException, IOException { - Document sdeleniDoc = Downloader.download("https://www.spsejecna.cz/user-student/record-list", JsessionId).get(); + Document sdeleniDoc = Downloader.download("https://www.spsejecna.cz/user-student/record-list").get(); Elements sdeleni = sdeleniDoc.select("ul.list li"); diff --git a/src/main/java/xyz/thastertyn/JecnaParse/Znamky.java b/src/main/java/xyz/thastertyn/JecnaParse/Znamky.java index 1bfcc38..33253b3 100644 --- a/src/main/java/xyz/thastertyn/JecnaParse/Znamky.java +++ b/src/main/java/xyz/thastertyn/JecnaParse/Znamky.java @@ -10,7 +10,7 @@ import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; -import xyz.thastertyn.Tuple.Pair; +import xyz.thastertyn.Tuples.Pair; public class Znamky { @@ -21,50 +21,10 @@ public class Znamky { // 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) + public void downloadZnamky(/*, int schoolYearId, int schoolYearHalfId*/) throws UnknownHostException, IOException { - Pair znamka = new Pair<>(grade, weight); - - grades.get(index).getValue1().getValue0().add(znamka); - } - - private void addSubject(String subject) - { - Pair>, Double> p = new Pair<>(new ArrayList>(), 0.0); - - grades.add(new Pair<>(subject, p)); - } - - private double getAverage(ArrayList> a) - { - try{ - double divident = 0; - double divisor = 0; - for(Pair p : a) - { - if(p.getValue0() == -1) - { - continue; - } - - divident += p.getValue0() * p.getValue1(); - divisor += p.getValue1(); - } - - double prumer = (double) divident / divisor; - return (double) Math.round(prumer * 100) / 100; - - }catch(ArithmeticException e) - { - return 0; - } - } - - public void downloadZnamky(final String Jsessionid/*, int schoolYearId, int schoolYearHalfId*/) throws UnknownHostException, IOException - { - 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", Jsessionid).get(); + Document znamkyDoc = Downloader.download("https://www.spsejecna.cz/score/student").get(); Elements rows = znamkyDoc.select("table.score").select("tr"); @@ -114,6 +74,8 @@ 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]"); @@ -131,8 +93,51 @@ public class Znamky { options.add(new Pair(rok, jeCelyRok)); }*/ + + wasDownloaded = true; + } + private void addGrade(int index, String subject, int grade, double weight) + { + Pair znamka = new Pair<>(grade, weight); + + grades.get(index).getValue1().getValue0().add(znamka); + } + + private void addSubject(String subject) + { + Pair>, Double> p = new Pair<>(new ArrayList>(), 0.0); + + grades.add(new Pair<>(subject, p)); + } + + private double getAverage(ArrayList> a) + { + try{ + double divident = 0; + double divisor = 0; + for(Pair p : a) + { + if(p.getValue0() == -1) + { + continue; + } + + divident += p.getValue0() * p.getValue1(); + divisor += p.getValue1(); + } + + double prumer = (double) divident / divisor; + return (double) Math.round(prumer * 100) / 100; + + }catch(ArithmeticException e) + { + return 0; + } + } + + public ArrayList>,Double>>> getGrades() { return grades; diff --git a/src/main/java/xyz/thastertyn/Tuple/Pair.java b/src/main/java/xyz/thastertyn/Tuples/Pair.java similarity index 95% rename from src/main/java/xyz/thastertyn/Tuple/Pair.java rename to src/main/java/xyz/thastertyn/Tuples/Pair.java index 1543589..e836568 100644 --- a/src/main/java/xyz/thastertyn/Tuple/Pair.java +++ b/src/main/java/xyz/thastertyn/Tuples/Pair.java @@ -1,10 +1,11 @@ -package xyz.thastertyn.Tuple; +package xyz.thastertyn.Tuples; /** * Ekvitalent Tuplu, ktery neni zabudovan v jave */ public class Pair { + private T1 value0; private T2 value1; diff --git a/src/main/java/xyz/thastertyn/Tuples/Triplet.java b/src/main/java/xyz/thastertyn/Tuples/Triplet.java new file mode 100644 index 0000000..31e10aa --- /dev/null +++ b/src/main/java/xyz/thastertyn/Tuples/Triplet.java @@ -0,0 +1,66 @@ +package xyz.thastertyn.Tuples; + +/** + * Ekvitalent Tuplu, ktery neni zabudovan v jave + */ +public class Triplet { + + private T1 value0; + private T2 value1; + private T3 value2; + + public Triplet(T1 value0, T2 value1, T3 value2) + { + this.value0 = value0; + this.value1 = value1; + this.value2 = value2; + } + + public Triplet() + { + + } + + public void put(T1 value0, T2 value1, T3 value2) + { + this.value0 = value0; + this.value1 = value1; + this.value2 = value2; + } + + public T1 getValue0() + { + return value0; + } + + public T2 getValue1() + { + return value1; + } + + public T3 getValue2() + { + return value2; + } + + public void setValue0(T1 value0) + { + this.value0 = value0; + } + + public void setValue1(T2 value1) + { + this.value1 = value1; + } + + public void setValue2(T3 value2) + { + this.value2 = value2; + } + + @Override + public String toString() + { + return "[" + value0 + ", " + value1 + "]"; + } +}