Mensi upravy, novy typ
This commit is contained in:
parent
7b7c00b866
commit
12f06c45ff
@ -11,7 +11,6 @@ import com.googlecode.lanterna.gui2.Label;
|
|||||||
import com.googlecode.lanterna.gui2.LinearLayout;
|
import com.googlecode.lanterna.gui2.LinearLayout;
|
||||||
import com.googlecode.lanterna.gui2.Panel;
|
import com.googlecode.lanterna.gui2.Panel;
|
||||||
import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
|
import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
|
||||||
import com.googlecode.lanterna.gui2.dialogs.MessageDialog;
|
|
||||||
|
|
||||||
import xyz.thastertyn.Display.Dialogs.OptionsDialog;
|
import xyz.thastertyn.Display.Dialogs.OptionsDialog;
|
||||||
import xyz.thastertyn.Tuples.Pair;
|
import xyz.thastertyn.Tuples.Pair;
|
||||||
@ -162,7 +161,7 @@ public class Znamky extends JecnaContent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showOptions(WindowBasedTextGUI textGUI) {
|
public void showOptions(WindowBasedTextGUI textGUI) {
|
||||||
OptionsDialog d = new OptionsDialog(znamky.getOptions());
|
OptionsDialog d = new OptionsDialog(znamky.getOptions().getValue0(), znamky.getOptions().getValue1());
|
||||||
|
|
||||||
d.showDialog(textGUI);
|
d.showDialog(textGUI);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package xyz.thastertyn.Display.Dialogs;
|
package xyz.thastertyn.Display.Dialogs;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import com.googlecode.lanterna.gui2.Button;
|
import com.googlecode.lanterna.gui2.Button;
|
||||||
@ -13,16 +12,11 @@ import com.googlecode.lanterna.gui2.Window;
|
|||||||
import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
|
import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
|
||||||
import com.googlecode.lanterna.gui2.dialogs.DialogWindow;
|
import com.googlecode.lanterna.gui2.dialogs.DialogWindow;
|
||||||
|
|
||||||
import xyz.thastertyn.Tuples.Pair;
|
import xyz.thastertyn.Types.Options;
|
||||||
|
|
||||||
public class OptionsDialog extends DialogWindow {
|
public class OptionsDialog extends DialogWindow {
|
||||||
|
|
||||||
|
public OptionsDialog(Options... options)
|
||||||
private int option0 = 0;
|
|
||||||
private int option1 = 0;
|
|
||||||
|
|
||||||
|
|
||||||
public OptionsDialog(Pair<ArrayList<String>, ArrayList<String>> options)
|
|
||||||
{
|
{
|
||||||
super("Choose from below");
|
super("Choose from below");
|
||||||
|
|
||||||
@ -31,12 +25,19 @@ public class OptionsDialog extends DialogWindow {
|
|||||||
.setLeftMarginSize(1)
|
.setLeftMarginSize(1)
|
||||||
.setRightMarginSize(1));
|
.setRightMarginSize(1));
|
||||||
|
|
||||||
new Panel().setLayoutManager(new GridLayout(3))
|
Panel optionPanel = new Panel().setLayoutManager(new GridLayout(3))
|
||||||
.addComponent(new ComboBox<>(options.getValue0(), options.getValue0().size() - 1))
|
|
||||||
.addComponent(new EmptySpace())
|
|
||||||
.addComponent(new ComboBox<>(options.getValue1(), options.getValue1().size() - 1))
|
|
||||||
.addTo(mainPanel);
|
.addTo(mainPanel);
|
||||||
|
|
||||||
|
for(int i = 0; i < options.length; i++)
|
||||||
|
{
|
||||||
|
optionPanel.addComponent(new ComboBox<>(options[i].getOptions()));
|
||||||
|
|
||||||
|
if(i != options.length - 1)
|
||||||
|
{
|
||||||
|
optionPanel.addComponent(new EmptySpace());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
new Panel()
|
new Panel()
|
||||||
.setLayoutManager(
|
.setLayoutManager(
|
||||||
new GridLayout(2).setHorizontalSpacing(1))
|
new GridLayout(2).setHorizontalSpacing(1))
|
||||||
|
@ -7,6 +7,7 @@ import java.io.FileReader;
|
|||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import javax.security.auth.login.CredentialException;
|
import javax.security.auth.login.CredentialException;
|
||||||
|
|
||||||
@ -43,6 +44,10 @@ public class LoginController {
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
login.loginJecna(data.getValue0(), data.getValue1());
|
login.loginJecna(data.getValue0(), data.getValue1());
|
||||||
|
}catch (TimeoutException e)
|
||||||
|
{
|
||||||
|
MessageDialog.showMessageDialog(textGUI, "Timeout", "The attempt to connect took too long.", MessageDialogButton.Retry,
|
||||||
|
MessageDialogButton.Abort);
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
MessageDialog.showMessageDialog(textGUI, "No Internet connection",
|
MessageDialog.showMessageDialog(textGUI, "No Internet connection",
|
||||||
"There seems to be no internet connection, reverting to cached data",
|
"There seems to be no internet connection, reverting to cached data",
|
||||||
@ -178,7 +183,7 @@ public class LoginController {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
login.loginJecna(user, pass);
|
login.loginJecna(user, pass);
|
||||||
} catch (CredentialException | IOException e) {
|
} catch (CredentialException | IOException | TimeoutException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,8 @@ public class Downloader {
|
|||||||
Connection c = Jsoup.connect(url)
|
Connection c = Jsoup.connect(url)
|
||||||
.header("Connection", "keep-alive")
|
.header("Connection", "keep-alive")
|
||||||
.cookie("role", "student")
|
.cookie("role", "student")
|
||||||
.cookie("JSESSIONID", JsessionId);
|
.cookie("JSESSIONID", JsessionId)
|
||||||
|
.timeout(10000);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package xyz.thastertyn.Scrape;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import javax.security.auth.login.CredentialException;
|
import javax.security.auth.login.CredentialException;
|
||||||
|
|
||||||
@ -18,7 +19,7 @@ public class Login {
|
|||||||
private long start;
|
private long start;
|
||||||
private long lastCheck;
|
private long lastCheck;
|
||||||
|
|
||||||
public void loginJecna(String user, String pass) throws UnknownHostException, IOException, CredentialException
|
public void loginJecna(String user, String pass) throws UnknownHostException, IOException, CredentialException, TimeoutException
|
||||||
{
|
{
|
||||||
//#region JSESSIONID
|
//#region JSESSIONID
|
||||||
Connection.Response response = Jsoup.connect("https://www.spsejecna.cz")
|
Connection.Response response = Jsoup.connect("https://www.spsejecna.cz")
|
||||||
@ -31,22 +32,17 @@ public class Login {
|
|||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region Token3
|
//#region Token3
|
||||||
String token3 = Jsoup.connect("https://www.spsejecna.cz/user/role?role=student")
|
String token3 = Downloader.download("https://www.spsejecna.cz/user/role?role=student")
|
||||||
.header("Connection", "keep-alive")
|
|
||||||
.cookie("JSESSIONID", Jsessionid)
|
|
||||||
.get()
|
.get()
|
||||||
.select("input[name=token3]")
|
.select("input[name=token3]")
|
||||||
.attr("value");
|
.attr("value");
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region Login
|
//#region Login
|
||||||
Jsoup.connect("https://www.spsejecna.cz/user/login")
|
Downloader.download("https://www.spsejecna.cz/user/login")
|
||||||
.method(Connection.Method.POST)
|
.method(Connection.Method.POST)
|
||||||
.header("Content-Type", "application/x-www-form-urlencoded")
|
.header("Content-Type", "application/x-www-form-urlencoded")
|
||||||
.header("Origin", "https://www.spsejecna.cz")
|
.header("Origin", "https://www.spsejecna.cz")
|
||||||
.header("Connection", "keep-alive")
|
|
||||||
.cookie("JSESSIONID", Jsessionid)
|
|
||||||
.cookie("role", "student")
|
|
||||||
.data("token3", token3)
|
.data("token3", token3)
|
||||||
.data("user", user)
|
.data("user", user)
|
||||||
.data("pass", pass)
|
.data("pass", pass)
|
||||||
@ -55,10 +51,7 @@ public class Login {
|
|||||||
.execute();
|
.execute();
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
Document test = Jsoup.connect("https://www.spsejecna.cz/score/student")
|
Document test = Downloader.download("https://www.spsejecna.cz/score/student")
|
||||||
.header("Connection", "keep-alive")
|
|
||||||
.cookie("JSESSIONID", Jsessionid)
|
|
||||||
.cookie("role", "student")
|
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
if(test.toString().contains("Pro pokračování se přihlaste do systému"))
|
if(test.toString().contains("Pro pokračování se přihlaste do systému"))
|
||||||
|
@ -11,18 +11,19 @@ import org.jsoup.nodes.Element;
|
|||||||
import org.jsoup.select.Elements;
|
import org.jsoup.select.Elements;
|
||||||
|
|
||||||
import xyz.thastertyn.Tuples.Pair;
|
import xyz.thastertyn.Tuples.Pair;
|
||||||
import xyz.thastertyn.Tuples.Triplet;
|
import xyz.thastertyn.Types.Option;
|
||||||
|
import xyz.thastertyn.Types.Options;
|
||||||
|
|
||||||
public class Znamky {
|
public class Znamky {
|
||||||
|
|
||||||
private boolean wasDownloaded;
|
private boolean wasDownloaded;
|
||||||
|
|
||||||
// schoolYear, schoolYearId
|
// schoolYear, schoolYearId
|
||||||
private ArrayList<Triplet<String, ArrayList<Pair<Integer, Double>>, Double>> test = new ArrayList<>();
|
|
||||||
private ArrayList<Pair<String, Pair<ArrayList<Pair<Integer, Double>>,Double>>> grades = new ArrayList<>();
|
private ArrayList<Pair<String, Pair<ArrayList<Pair<Integer, Double>>,Double>>> grades = new ArrayList<>();
|
||||||
|
|
||||||
// Integer znaci id roku, boolean jestli je jen prvni nebo i druhe pololeti
|
// Integer znaci id roku, boolean jestli je jen prvni nebo i druhe pololeti
|
||||||
private Pair<ArrayList<Pair<String, String>>, ArrayList<Pair<String, String>>> options = new Pair<>(new ArrayList<Pair<String, String>>(), new ArrayList<Pair<String, String>>());
|
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(/*, int schoolYearId, int schoolYearHalfId*/) throws UnknownHostException, IOException
|
||||||
{
|
{
|
||||||
@ -85,12 +86,12 @@ public class Znamky {
|
|||||||
|
|
||||||
for(Element e : schoolYear)
|
for(Element e : schoolYear)
|
||||||
{
|
{
|
||||||
options.getValue0().add(e.attr("value"));
|
this.schoolYearOptions.addOption(new Option(e.text(), e.attr("value")));
|
||||||
}
|
}
|
||||||
|
|
||||||
for(Element e : schoolYearId)
|
for(Element e : schoolYearId)
|
||||||
{
|
{
|
||||||
options.getValue1().add(new Pair<>(e.attr("value", e.text()));
|
this.schoolHalfYearOptions.addOption(new Option(e.text(), e.attr("value")));
|
||||||
}
|
}
|
||||||
|
|
||||||
wasDownloaded = true;
|
wasDownloaded = true;
|
||||||
@ -141,9 +142,9 @@ public class Znamky {
|
|||||||
return grades;
|
return grades;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pair<ArrayList<String>, ArrayList<String>> getOptions()
|
public Pair<Options, Options> getOptions()
|
||||||
{
|
{
|
||||||
return options;
|
return new Pair<Options, Options>(schoolYearOptions, schoolHalfYearOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -61,6 +61,6 @@ public class Triplet<T1, T2, T3> {
|
|||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return "[" + value0 + ", " + value1 + "]";
|
return "[" + value0 + ", " + value1 + "," + value2 + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
27
src/main/java/xyz/thastertyn/Types/Option.java
Normal file
27
src/main/java/xyz/thastertyn/Types/Option.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package xyz.thastertyn.Types;
|
||||||
|
|
||||||
|
public class Option {
|
||||||
|
|
||||||
|
private String text;
|
||||||
|
private String value;
|
||||||
|
public Option(String text, String value) {
|
||||||
|
this.text = text;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
public String getText() {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
public void setText(String text) {
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
public void setValue(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
}
|
32
src/main/java/xyz/thastertyn/Types/Options.java
Normal file
32
src/main/java/xyz/thastertyn/Types/Options.java
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package xyz.thastertyn.Types;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class Options {
|
||||||
|
|
||||||
|
private ArrayList<Option> options = new ArrayList<>();
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
public Options(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addOption(Option o)
|
||||||
|
{
|
||||||
|
options.add(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Option> getOptions() {
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
public void setOptions(ArrayList<Option> options) {
|
||||||
|
this.options = options;
|
||||||
|
}
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user