diff --git a/src/main/java/xyz/thastertyn/App.java b/src/main/java/xyz/thastertyn/App.java index e0f106e..e23ec75 100644 --- a/src/main/java/xyz/thastertyn/App.java +++ b/src/main/java/xyz/thastertyn/App.java @@ -1,9 +1,5 @@ package xyz.thastertyn; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.plaf.FontUIResource; - import xyz.thastertyn.UserInterface.MainWindow; /** diff --git a/src/main/java/xyz/thastertyn/Login/Login.java b/src/main/java/xyz/thastertyn/Login/Login.java index b281ecf..c9ad0e5 100644 --- a/src/main/java/xyz/thastertyn/Login/Login.java +++ b/src/main/java/xyz/thastertyn/Login/Login.java @@ -65,7 +65,7 @@ public class Login { lastCheck = start; } - /*public void loginJidelna() throws UnknownHostException, IOException + public void loginJidelna(String user, String pass) throws UnknownHostException, IOException { //#region JSESSIONID Connection.Response jidelna = Jsoup.connect("https://objednavky.jidelnasokolska.cz/") @@ -94,13 +94,13 @@ public class Login { //#endregion //#region Login - Connection.Response jidelnaLogin = Jsoup.connect("https://objednavky.jidelnasokolska.cz/j_spring_security_check") + Jsoup.connect("https://objednavky.jidelnasokolska.cz/j_spring_security_check") .header("Connection", "keep-alive") .header("Content-Type", "application/x-www-form-urlencoded") .cookie("XSRF-TOKEN", XSRF_TOKEN) .cookie("JSESSIONID", jidelnaJSESSIONID) - .data("j_username", Credentials.user) - .data("j_password", Credentials.pass) + .data("j_username", user) + .data("j_password", pass) .data("terminal", "false") .data("type", "web") .data("_csrf", XSRF_TOKEN) @@ -108,5 +108,5 @@ public class Login { .method(Method.POST) .execute(); //#endregion - }*/ + } } diff --git a/src/main/java/xyz/thastertyn/Scrape/Znamky.java b/src/main/java/xyz/thastertyn/Scrape/Znamky.java index 8f91f30..571e36a 100644 --- a/src/main/java/xyz/thastertyn/Scrape/Znamky.java +++ b/src/main/java/xyz/thastertyn/Scrape/Znamky.java @@ -10,6 +10,7 @@ import org.jsoup.nodes.Element; import org.jsoup.select.Elements; import xyz.thastertyn.Tuples.Pair; +import xyz.thastertyn.Types.Choice; import xyz.thastertyn.Types.Option; import xyz.thastertyn.Types.Options; import xyz.thastertyn.Types.Predmet; @@ -26,11 +27,24 @@ public class Znamky { private Options schoolYearOptions = new Options("Skolni R."); private Options schoolHalfYearOptions = new Options("Pololeti"); - public void downloadZnamky(/*, int schoolYearId, int schoolYearHalfId*/) throws UnknownHostException, IOException + public void downloadZnamky() throws UnknownHostException, IOException { - //String url = String.format("https://www.spsejecna.cz/score/student?schoolYearId=%d&schoolYearHalfId=%d", schoolYearId, schoolYearHalfId); - Document znamkyDokumentHTML = Downloader.download("https://www.spsejecna.cz/score/student").get(); - + download("https://www.spsejecna.cz/score/student"); + } + + public void downloadZnamky(Choice choice) throws UnknownHostException, IOException + { + download(String.format( + "https://www.spsejecna.cz/score/student?schoolYearId=%s&schoolYearHalfId=%s", + choice.getChoices().get(0), + choice.getChoices().get(1))); + } + + private void download(String url) throws UnknownHostException, IOException + { + //String url = + Document znamkyDokumentHTML = Downloader.download(url).get(); + // Predmety ulozene v Elements[] radkyPredmetuHTML = znamkyDokumentHTML .select("table.score") diff --git a/src/main/java/xyz/thastertyn/Types/Choice.java b/src/main/java/xyz/thastertyn/Types/Choice.java new file mode 100644 index 0000000..d6c1116 --- /dev/null +++ b/src/main/java/xyz/thastertyn/Types/Choice.java @@ -0,0 +1,18 @@ +package xyz.thastertyn.Types; + +import java.util.ArrayList; +import java.util.Arrays; + +public class Choice { + + private ArrayList choices; + public Choice(String... choices) + { + this.choices.addAll(Arrays.asList(choices)); + } + + public ArrayList getChoices() + { + return choices; + } +} diff --git a/src/main/java/xyz/thastertyn/UserInterface/Content/JecnaContent.java b/src/main/java/xyz/thastertyn/UserInterface/Content/JecnaContent.java index ee84643..24e7420 100644 --- a/src/main/java/xyz/thastertyn/UserInterface/Content/JecnaContent.java +++ b/src/main/java/xyz/thastertyn/UserInterface/Content/JecnaContent.java @@ -1,7 +1,9 @@ package xyz.thastertyn.UserInterface.Content; import com.googlecode.lanterna.gui2.WindowBasedTextGUI; -import com.googlecode.lanterna.gui2.dialogs.MessageDialog; + +import xyz.thastertyn.Types.Choice; + import com.googlecode.lanterna.gui2.Panel; import com.googlecode.lanterna.gui2.Label; @@ -11,8 +13,10 @@ import com.googlecode.lanterna.gui2.Label; public abstract class JecnaContent { public abstract Panel getPanel(); - public abstract void download(); + public abstract void downloadDefault(); + protected abstract void download(Choice choice); public abstract boolean hasStarted(); public abstract Label getLabel(); public abstract void showOptions(final WindowBasedTextGUI textGUI); + protected abstract void setGUI(); } diff --git a/src/main/java/xyz/thastertyn/UserInterface/Content/OmluvnyList.java b/src/main/java/xyz/thastertyn/UserInterface/Content/OmluvnyList.java index 55489ac..d02348a 100644 --- a/src/main/java/xyz/thastertyn/UserInterface/Content/OmluvnyList.java +++ b/src/main/java/xyz/thastertyn/UserInterface/Content/OmluvnyList.java @@ -9,6 +9,7 @@ import com.googlecode.lanterna.gui2.Panel; import com.googlecode.lanterna.gui2.WindowBasedTextGUI; import xyz.thastertyn.Tuples.Pair; +import xyz.thastertyn.Types.Choice; public class OmluvnyList extends JecnaContent{ @@ -19,16 +20,18 @@ public class OmluvnyList extends JecnaContent{ private boolean hasStarted = false; @Override - public void download() { + public void downloadDefault() + { + download(null); + } + + @Override + protected void download(Choice choice) + { try{ omluvnyList.downloadOmluvnyList(); + setGUI(); - ArrayList> a = omluvnyList.getData(); - - for(Pair p : a) - { - omluvnyPanel.addComponent(new Label(p.getValue0() + " - " + p.getValue1())); - } hasStarted = true; }catch(UnknownHostException e) { @@ -39,6 +42,17 @@ public class OmluvnyList extends JecnaContent{ } } + @Override + protected void setGUI() + { + ArrayList> a = omluvnyList.getData(); + + for(Pair p : a) + { + omluvnyPanel.addComponent(new Label(p.getValue0() + " - " + p.getValue1())); + } + } + @Override public Panel getPanel() { return omluvnyPanel; diff --git a/src/main/java/xyz/thastertyn/UserInterface/Content/Rozvrh.java b/src/main/java/xyz/thastertyn/UserInterface/Content/Rozvrh.java index 27b6a7d..8b8244b 100644 --- a/src/main/java/xyz/thastertyn/UserInterface/Content/Rozvrh.java +++ b/src/main/java/xyz/thastertyn/UserInterface/Content/Rozvrh.java @@ -6,9 +6,10 @@ 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.dialogs.MessageDialog; import com.googlecode.lanterna.gui2.table.Table; +import xyz.thastertyn.Types.Choice; + public class Rozvrh extends JecnaContent { private Panel rozvrhPanel = new Panel(); @@ -25,26 +26,18 @@ public class Rozvrh extends JecnaContent { Table t = new Table<>(labels); @Override - public void download() + public void downloadDefault() + { + download(null); + } + + @Override + protected void download(Choice choice) { try{ rozvrh.downloadRozvrh(); - - String[][] rozvrhArray = rozvrh.getRozvrh(); - - String[] den = new String[11]; - - for(int i = 0; i < rozvrhArray.length; i++) - { - den[0] = daysLabels[i]; - for(int j = 1; j < rozvrhArray[i].length + 1; j++) - { - den[j] = (rozvrhArray[i][j - 1].isBlank()) ? " - " : rozvrhArray[i][j - 1]; - } - - t.getTableModel().addRow(den); - } - rozvrhPanel.addComponent(t); + setGUI(); + hasStarted = true; }catch(UnknownHostException e) { @@ -55,6 +48,26 @@ public class Rozvrh extends JecnaContent { } } + @Override + protected void setGUI() + { + String[][] rozvrhArray = rozvrh.getRozvrh(); + + String[] den = new String[11]; + + for(int i = 0; i < rozvrhArray.length; i++) + { + den[0] = daysLabels[i]; + for(int j = 1; j < rozvrhArray[i].length + 1; j++) + { + den[j] = (rozvrhArray[i][j - 1].isBlank()) ? " - " : rozvrhArray[i][j - 1]; + } + + t.getTableModel().addRow(den); + } + rozvrhPanel.addComponent(t); + } + @Override public boolean hasStarted() { diff --git a/src/main/java/xyz/thastertyn/UserInterface/Content/Sdeleni.java b/src/main/java/xyz/thastertyn/UserInterface/Content/Sdeleni.java index ea6bbe0..36a95e3 100644 --- a/src/main/java/xyz/thastertyn/UserInterface/Content/Sdeleni.java +++ b/src/main/java/xyz/thastertyn/UserInterface/Content/Sdeleni.java @@ -9,7 +9,8 @@ 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 com.googlecode.lanterna.gui2.dialogs.MessageDialog; + +import xyz.thastertyn.Types.Choice; public class Sdeleni extends JecnaContent { @@ -20,33 +21,40 @@ public class Sdeleni extends JecnaContent { private boolean hasStarted = false; + @Override + public void downloadDefault() + { + download(null); + } @Override - public void download() + protected void download(Choice choice) { - if(!hasStarted) + try{ + sdeleni.downloadSdeleni(); + + hasStarted = true; + }catch(UnknownHostException e) { - try{ - sdeleniPanel.setLayoutManager(new GridLayout(1) - .setLeftMarginSize(1) - .setRightMarginSize(1)); - sdeleni.downloadSdeleni(); + }catch(IOException e) + { + + } + } - ArrayList sdeleniList = sdeleni.getSdeleni(); + @Override + protected void setGUI() + { + sdeleniPanel.setLayoutManager(new GridLayout(1) + .setLeftMarginSize(1) + .setRightMarginSize(1)); - for(String s : sdeleniList) - { - sdeleniPanel.addComponent(new Label(s)); - } - hasStarted = true; - }catch(UnknownHostException e) - { + ArrayList sdeleniList = sdeleni.getSdeleni(); - }catch(IOException e) - { - - } + for(String s : sdeleniList) + { + sdeleniPanel.addComponent(new Label(s)); } } diff --git a/src/main/java/xyz/thastertyn/UserInterface/Content/Znamky.java b/src/main/java/xyz/thastertyn/UserInterface/Content/Znamky.java index 6cab6fc..74911d5 100644 --- a/src/main/java/xyz/thastertyn/UserInterface/Content/Znamky.java +++ b/src/main/java/xyz/thastertyn/UserInterface/Content/Znamky.java @@ -15,6 +15,7 @@ import com.googlecode.lanterna.gui2.LinearLayout; import com.googlecode.lanterna.gui2.Panel; import com.googlecode.lanterna.gui2.WindowBasedTextGUI; +import xyz.thastertyn.Types.Choice; import xyz.thastertyn.Types.Predmet; import xyz.thastertyn.Types.Znamka; import xyz.thastertyn.UserInterface.Dialogs.OptionsDialog; @@ -49,66 +50,23 @@ public class Znamky extends JecnaContent { private boolean hasStarted = false; @Override - public void download() + public void downloadDefault() + { + download(null); + } + + @Override + protected void download(Choice choice) { try{ - znamky.downloadZnamky(); - - ArrayList predmety = znamky.getPredmety(); - - HashMap barvy = new HashMap<>(); - barvy.put(1, new SimpleTheme(ANSI.BLACK, VYBORNY)); - barvy.put(2, new SimpleTheme(ANSI.BLACK, CHVALITEBNY)); - barvy.put(3, new SimpleTheme(ANSI.BLACK, DOBRY)); - barvy.put(4, new SimpleTheme(ANSI.BLACK, DOSTATECNY)); - barvy.put(5, new SimpleTheme(ANSI.BLACK, NEDOSTATECNY)); - barvy.put(-1, new SimpleTheme(ANSI.WHITE, NEHODNOCEN)); - - // Sloupec pro jmena predmetu - Panel jmemaPredmetu = new Panel() - .setLayoutManager(new LinearLayout(Direction.VERTICAL)) - .setLayoutData(ALIGN_LEFT) - .addTo(mainPanel); - - // Sloupec pro znamky z predmetu - Panel znamky = new Panel() - .setLayoutManager(new LinearLayout(Direction.VERTICAL)) - .setLayoutData(ALIGN_LEFT) - .addTo(mainPanel); - - // Sloupec pro vyslednou znamku - Panel vysledneZnamky = new Panel() - .setLayoutManager(new LinearLayout(Direction.VERTICAL)) - .setLayoutData(ALIGN_RIGHT) - .addTo(mainPanel); - - for(Predmet predmet : predmety) + if(choice != null) { - Panel jednotliveZnamky = new Panel() - .setLayoutManager(new LinearLayout(Direction.HORIZONTAL)) - .addTo(znamky); - - if(predmet.getZnamky().isEmpty()) - { - jednotliveZnamky.addComponent(new Label("")); - } - - for(Znamka znamka : predmet.getZnamky()) - { - Label znamkaLabel = new Label(znamka.getText()); - znamkaLabel.setTheme(barvy.get(znamka.getZnamka())); - jednotliveZnamky.addComponent(znamkaLabel); - } - - double prumer = predmet.getPrumer(); - - Label vysl = new Label(String.format("%.2f", prumer)); - - vysl.setTheme(barvy.get((int) Math.round(prumer))); - - jmemaPredmetu.addComponent(new Label(predmet.getJmenoPredmetu())); - vysledneZnamky.addComponent(vysl); + znamky.downloadZnamky(choice); + }else{ + znamky.downloadZnamky(); } + + setGUI(); hasStarted = true; }catch(IOException e) @@ -117,6 +75,67 @@ public class Znamky extends JecnaContent { } } + @Override + protected void setGUI() + { + ArrayList predmety = znamky.getPredmety(); + + HashMap barvy = new HashMap<>(); + barvy.put(1, new SimpleTheme(ANSI.BLACK, VYBORNY)); + barvy.put(2, new SimpleTheme(ANSI.BLACK, CHVALITEBNY)); + barvy.put(3, new SimpleTheme(ANSI.BLACK, DOBRY)); + barvy.put(4, new SimpleTheme(ANSI.BLACK, DOSTATECNY)); + barvy.put(5, new SimpleTheme(ANSI.BLACK, NEDOSTATECNY)); + barvy.put(-1, new SimpleTheme(ANSI.WHITE, NEHODNOCEN)); + + // Sloupec pro jmena predmetu + Panel jmemaPredmetu = new Panel() + .setLayoutManager(new LinearLayout(Direction.VERTICAL)) + .setLayoutData(ALIGN_LEFT) + .addTo(mainPanel); + + // Sloupec pro znamky z predmetu + Panel znamky = new Panel() + .setLayoutManager(new LinearLayout(Direction.VERTICAL)) + .setLayoutData(ALIGN_LEFT) + .addTo(mainPanel); + + // Sloupec pro vyslednou znamku + Panel vysledneZnamky = new Panel() + .setLayoutManager(new LinearLayout(Direction.VERTICAL)) + .setLayoutData(ALIGN_RIGHT) + .addTo(mainPanel); + + for(Predmet predmet : predmety) + { + Panel jednotliveZnamky = new Panel() + .setLayoutManager(new LinearLayout(Direction.HORIZONTAL)) + .addTo(znamky); + + if(predmet.getZnamky().isEmpty()) + { + jednotliveZnamky.addComponent(new Label("")); + } + + for(Znamka znamka : predmet.getZnamky()) + { + Label znamkaLabel = new Label(znamka.getText()); + znamkaLabel.setTheme(barvy.get(znamka.getZnamka())); + jednotliveZnamky.addComponent(znamkaLabel); + } + + double prumer = predmet.getPrumer(); + + Label vysl = new Label(String.format("%.2f", prumer)); + + vysl.setTheme(barvy.get((int) Math.round(prumer))); + + jmemaPredmetu.addComponent(new Label(predmet.getJmenoPredmetu())); + vysledneZnamky.addComponent(vysl); + } + } + + @Override public Panel getPanel() { @@ -139,6 +158,11 @@ public class Znamky extends JecnaContent { public void showOptions(WindowBasedTextGUI textGUI) { OptionsDialog d = new OptionsDialog(znamky.getOptions().getValue0(), znamky.getOptions().getValue1()); - d.showDialog(textGUI); + Choice c = d.showDialog(textGUI); + + if(c != null) + { + download(c); + } } } \ No newline at end of file diff --git a/src/main/java/xyz/thastertyn/UserInterface/Dialogs/OptionsDialog.java b/src/main/java/xyz/thastertyn/UserInterface/Dialogs/OptionsDialog.java index 6cce016..bda89cc 100644 --- a/src/main/java/xyz/thastertyn/UserInterface/Dialogs/OptionsDialog.java +++ b/src/main/java/xyz/thastertyn/UserInterface/Dialogs/OptionsDialog.java @@ -1,6 +1,9 @@ package xyz.thastertyn.UserInterface.Dialogs; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; + import com.googlecode.lanterna.gui2.Button; import com.googlecode.lanterna.gui2.ComboBox; @@ -12,14 +15,27 @@ import com.googlecode.lanterna.gui2.Window; import com.googlecode.lanterna.gui2.WindowBasedTextGUI; import com.googlecode.lanterna.gui2.dialogs.DialogWindow; +import xyz.thastertyn.Types.Choice; +import xyz.thastertyn.Types.Option; import xyz.thastertyn.Types.Options; public class OptionsDialog extends DialogWindow { + + private List> boxs; + + private boolean useData = false; public OptionsDialog(Options... options) { super("Choose from below"); + boxs = new ArrayList<>(); + + for(Options o : options) + { + boxs.add(new ComboBox