trying to optimize a bit and improve looks
This commit is contained in:
parent
94ab336ddb
commit
b4c1e53c83
@ -1,10 +1,13 @@
|
|||||||
package xyz.thastertyn.Scrape;
|
package xyz.thastertyn.Scrape;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.SocketTimeoutException;
|
|
||||||
import java.net.UnknownHostException;
|
import xyz.thastertyn.Types.Choice;
|
||||||
|
import xyz.thastertyn.Types.Options;
|
||||||
|
|
||||||
public abstract class JecnaScrape {
|
public abstract class JecnaScrape {
|
||||||
|
|
||||||
public abstract void download() throws SocketTimeoutException, UnknownHostException, IOException;
|
public abstract Options[] getOptions();
|
||||||
|
public abstract void download(Choice choice) throws IOException;
|
||||||
|
public abstract void download() throws IOException;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,28 @@
|
|||||||
package xyz.thastertyn.Scrape;
|
package xyz.thastertyn.Scrape;
|
||||||
|
|
||||||
public class Jidelna {
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import xyz.thastertyn.Types.Choice;
|
||||||
|
import xyz.thastertyn.Types.Options;
|
||||||
|
|
||||||
|
public class Jidelna extends JecnaScrape {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Options[] getOptions() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new UnsupportedOperationException("Unimplemented method 'getOptions'");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void download(Choice choice) throws IOException {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new UnsupportedOperationException("Unimplemented method 'download'");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void download() throws IOException {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new UnsupportedOperationException("Unimplemented method 'download'");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package xyz.thastertyn.Scrape;
|
package xyz.thastertyn.Scrape;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
@ -9,12 +8,15 @@ 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.Types.Choice;
|
||||||
|
import xyz.thastertyn.Types.Options;
|
||||||
|
|
||||||
public class OmluvnyList {
|
public class OmluvnyList extends JecnaScrape {
|
||||||
|
|
||||||
private ArrayList<Pair<String, String>> data = new ArrayList<>();
|
private ArrayList<Pair<String, String>> data = new ArrayList<>();
|
||||||
|
|
||||||
public void downloadOmluvnyList() throws UnknownHostException, IOException
|
@Override
|
||||||
|
public void download() throws IOException
|
||||||
{
|
{
|
||||||
Document omluvnyListDokumentHTML = Downloader.download("https://www.spsejecna.cz/absence/student").get();
|
Document omluvnyListDokumentHTML = Downloader.download("https://www.spsejecna.cz/absence/student").get();
|
||||||
|
|
||||||
@ -39,4 +41,16 @@ public class OmluvnyList {
|
|||||||
{
|
{
|
||||||
return (!data.isEmpty()) ? data.toString() : null;
|
return (!data.isEmpty()) ? data.toString() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Options[] getOptions() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new UnsupportedOperationException("Unimplemented method 'getOptions'");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void download(Choice choice) throws IOException {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new UnsupportedOperationException("Unimplemented method 'download'");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,10 +9,13 @@ import org.jsoup.nodes.Document;
|
|||||||
import org.jsoup.nodes.Element;
|
import org.jsoup.nodes.Element;
|
||||||
import org.jsoup.select.Elements;
|
import org.jsoup.select.Elements;
|
||||||
|
|
||||||
|
import xyz.thastertyn.Types.Choice;
|
||||||
|
import xyz.thastertyn.Types.Options;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Jeden radek v rozvrhu
|
* Jeden radek v rozvrhu
|
||||||
*/
|
*/
|
||||||
public class Rozvrh {
|
public class Rozvrh extends JecnaScrape {
|
||||||
|
|
||||||
private String[][] rozvrh = new String[5][10];
|
private String[][] rozvrh = new String[5][10];
|
||||||
|
|
||||||
@ -23,7 +26,8 @@ public class Rozvrh {
|
|||||||
* @throws UnknownHostException kdyz neni pripojeni k internetu
|
* @throws UnknownHostException kdyz neni pripojeni k internetu
|
||||||
* @throws IOException ostatni exceptiony nejsou dulezite, tak jsou zahrnuty v jednom
|
* @throws IOException ostatni exceptiony nejsou dulezite, tak jsou zahrnuty v jednom
|
||||||
*/
|
*/
|
||||||
public void downloadRozvrh() throws UnknownHostException, IOException
|
@Override
|
||||||
|
public void download() throws IOException
|
||||||
{
|
{
|
||||||
Document rozvrhDokumentHTML = Downloader.download("https://www.spsejecna.cz/timetable/class").get();
|
Document rozvrhDokumentHTML = Downloader.download("https://www.spsejecna.cz/timetable/class").get();
|
||||||
|
|
||||||
@ -71,4 +75,16 @@ public class Rozvrh {
|
|||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Options[] getOptions() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new UnsupportedOperationException("Unimplemented method 'getOptions'");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void download(Choice choice) throws IOException {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new UnsupportedOperationException("Unimplemented method 'download'");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,11 +8,14 @@ import org.jsoup.nodes.Document;
|
|||||||
import org.jsoup.nodes.Element;
|
import org.jsoup.nodes.Element;
|
||||||
import org.jsoup.select.Elements;
|
import org.jsoup.select.Elements;
|
||||||
|
|
||||||
public class Sdeleni {
|
import xyz.thastertyn.Types.Choice;
|
||||||
|
import xyz.thastertyn.Types.Options;
|
||||||
|
|
||||||
|
public class Sdeleni extends JecnaScrape {
|
||||||
|
|
||||||
ArrayList<String> sdeleniList = new ArrayList<>();
|
ArrayList<String> sdeleniList = new ArrayList<>();
|
||||||
|
|
||||||
public void downloadSdeleni() throws UnknownHostException, IOException
|
public void download() throws UnknownHostException, IOException
|
||||||
{
|
{
|
||||||
Document sdeleniDoc = Downloader.download("https://www.spsejecna.cz/user-student/record-list").get();
|
Document sdeleniDoc = Downloader.download("https://www.spsejecna.cz/user-student/record-list").get();
|
||||||
|
|
||||||
@ -43,4 +46,16 @@ public class Sdeleni {
|
|||||||
{
|
{
|
||||||
return sdeleniList;
|
return sdeleniList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Options[] getOptions() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new UnsupportedOperationException("Unimplemented method 'getOptions'");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void download(Choice choice) throws IOException {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new UnsupportedOperationException("Unimplemented method 'download'");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ import xyz.thastertyn.Types.Options;
|
|||||||
import xyz.thastertyn.Types.Predmet;
|
import xyz.thastertyn.Types.Predmet;
|
||||||
import xyz.thastertyn.Types.Znamka;
|
import xyz.thastertyn.Types.Znamka;
|
||||||
|
|
||||||
public class Znamky {
|
public class Znamky extends JecnaScrape {
|
||||||
|
|
||||||
private boolean wasDownloaded;
|
private boolean wasDownloaded;
|
||||||
|
|
||||||
@ -27,12 +27,13 @@ public class Znamky {
|
|||||||
private Options schoolYearOptions = new Options("Skolni R.");
|
private Options schoolYearOptions = new Options("Skolni R.");
|
||||||
private Options schoolHalfYearOptions = new Options("Pololeti");
|
private Options schoolHalfYearOptions = new Options("Pololeti");
|
||||||
|
|
||||||
public void downloadZnamky() throws UnknownHostException, IOException
|
public void download() throws UnknownHostException, IOException
|
||||||
{
|
{
|
||||||
download("https://www.spsejecna.cz/score/student");
|
download("https://www.spsejecna.cz/score/student");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void downloadZnamky(Choice choice) throws SocketTimeoutException, UnknownHostException, IOException
|
@Override
|
||||||
|
public void download(Choice choice) throws IOException
|
||||||
{
|
{
|
||||||
download(String.format(
|
download(String.format(
|
||||||
"https://www.spsejecna.cz/score/student?schoolYearId=%s&schoolYearHalfId=%s",
|
"https://www.spsejecna.cz/score/student?schoolYearId=%s&schoolYearHalfId=%s",
|
||||||
|
@ -6,8 +6,10 @@ import com.googlecode.lanterna.gui2.Label;
|
|||||||
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 xyz.thastertyn.Scrape.JecnaScrape;
|
||||||
import xyz.thastertyn.Types.Choice;
|
import xyz.thastertyn.Types.Choice;
|
||||||
import xyz.thastertyn.UserInterface.UpdateListener;
|
import xyz.thastertyn.UserInterface.UpdateListener;
|
||||||
|
import xyz.thastertyn.UserInterface.Dialogs.OptionsDialog;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -22,8 +24,19 @@ public abstract class JecnaContent {
|
|||||||
|
|
||||||
protected abstract void setGUI();
|
protected abstract void setGUI();
|
||||||
protected abstract void download(Choice choice) throws IOException;
|
protected abstract void download(Choice choice) throws IOException;
|
||||||
public abstract void showOptions(final WindowBasedTextGUI textGUI) throws IOException;
|
|
||||||
public abstract void downloadDefault() throws IOException;
|
public abstract void downloadDefault() throws IOException;
|
||||||
|
protected JecnaScrape scraper;
|
||||||
|
|
||||||
|
public void showOptions(WindowBasedTextGUI textGUI) throws IOException {
|
||||||
|
OptionsDialog d = new OptionsDialog(scraper.getOptions());
|
||||||
|
|
||||||
|
Choice c = d.showDialog(textGUI);
|
||||||
|
|
||||||
|
if(c != null)
|
||||||
|
{
|
||||||
|
download(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Panel getPanel()
|
public Panel getPanel()
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package xyz.thastertyn.UserInterface.Content;
|
package xyz.thastertyn.UserInterface.Content;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import com.googlecode.lanterna.gui2.Label;
|
import com.googlecode.lanterna.gui2.Label;
|
||||||
@ -26,26 +25,26 @@ public class OmluvnyList extends JecnaContent{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void downloadDefault()
|
public void downloadDefault() throws IOException
|
||||||
{
|
{
|
||||||
download(null);
|
download(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void download(Choice choice)
|
protected void download(Choice choice) throws IOException
|
||||||
{
|
{
|
||||||
try{
|
omluvnyList = new xyz.thastertyn.Scrape.OmluvnyList();
|
||||||
omluvnyList.downloadOmluvnyList();
|
if(choice != null)
|
||||||
|
{
|
||||||
|
omluvnyList.download(choice);
|
||||||
|
setGUI();
|
||||||
|
listener.updatePanel();
|
||||||
|
}else{
|
||||||
|
omluvnyList.download();
|
||||||
setGUI();
|
setGUI();
|
||||||
|
|
||||||
hasStarted = true;
|
|
||||||
}catch(UnknownHostException e)
|
|
||||||
{
|
|
||||||
// omluvnyPanel.addComponent(new Label("A connection error occurred"));
|
|
||||||
}catch(IOException e)
|
|
||||||
{
|
|
||||||
// omluvnyPanel.addComponent(new Label("An error occurred"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
super.hasStarted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -41,7 +41,7 @@ public class Rozvrh extends JecnaContent {
|
|||||||
protected void download(Choice choice)
|
protected void download(Choice choice)
|
||||||
{
|
{
|
||||||
try{
|
try{
|
||||||
rozvrh.downloadRozvrh();
|
rozvrh.download();
|
||||||
setGUI();
|
setGUI();
|
||||||
|
|
||||||
hasStarted = true;
|
hasStarted = true;
|
||||||
|
@ -8,7 +8,6 @@ import java.util.ArrayList;
|
|||||||
import com.googlecode.lanterna.gui2.GridLayout;
|
import com.googlecode.lanterna.gui2.GridLayout;
|
||||||
import com.googlecode.lanterna.gui2.Label;
|
import com.googlecode.lanterna.gui2.Label;
|
||||||
import com.googlecode.lanterna.gui2.Panel;
|
import com.googlecode.lanterna.gui2.Panel;
|
||||||
import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
|
|
||||||
|
|
||||||
import xyz.thastertyn.Types.Choice;
|
import xyz.thastertyn.Types.Choice;
|
||||||
import xyz.thastertyn.UserInterface.UpdateListener;
|
import xyz.thastertyn.UserInterface.UpdateListener;
|
||||||
@ -20,33 +19,35 @@ public class Sdeleni extends JecnaContent {
|
|||||||
|
|
||||||
private xyz.thastertyn.Scrape.Sdeleni sdeleni = new xyz.thastertyn.Scrape.Sdeleni();
|
private xyz.thastertyn.Scrape.Sdeleni sdeleni = new xyz.thastertyn.Scrape.Sdeleni();
|
||||||
|
|
||||||
private boolean hasStarted = false;
|
|
||||||
|
|
||||||
public Sdeleni(UpdateListener listener)
|
public Sdeleni(UpdateListener listener)
|
||||||
{
|
{
|
||||||
|
super.mainPanel = this.mainPanel;
|
||||||
|
super.borderLabel = this.borderLabel;
|
||||||
|
super.scraper = this.sdeleni;
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void downloadDefault()
|
public void downloadDefault() throws IOException
|
||||||
{
|
{
|
||||||
download(null);
|
download(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void download(Choice choice)
|
protected void download(Choice choice) throws IOException
|
||||||
{
|
{
|
||||||
try{
|
sdeleni = new xyz.thastertyn.Scrape.Sdeleni();
|
||||||
sdeleni.downloadSdeleni();
|
if(choice != null)
|
||||||
|
|
||||||
hasStarted = true;
|
|
||||||
}catch(UnknownHostException e)
|
|
||||||
{
|
{
|
||||||
|
sdeleni.download(choice);
|
||||||
}catch(IOException e)
|
setGUI();
|
||||||
{
|
listener.updatePanel();
|
||||||
|
}else{
|
||||||
|
sdeleni.download();
|
||||||
|
setGUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
super.hasStarted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -58,30 +59,6 @@ public class Sdeleni extends JecnaContent {
|
|||||||
|
|
||||||
ArrayList<String> sdeleniList = sdeleni.getSdeleni();
|
ArrayList<String> sdeleniList = sdeleni.getSdeleni();
|
||||||
|
|
||||||
for(String s : sdeleniList)
|
sdeleniList.forEach(s -> sdeleniPanel.addComponent(new Label(s)));
|
||||||
{
|
|
||||||
sdeleniPanel.addComponent(new Label(s));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Label getLabel() {
|
|
||||||
return borderLabel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Panel getPanel() {
|
|
||||||
return sdeleniPanel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasStarted() {
|
|
||||||
return hasStarted;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void showOptions(WindowBasedTextGUI textGUI) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
throw new UnsupportedOperationException("Unimplemented method 'getOptions'");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,13 +13,11 @@ import com.googlecode.lanterna.gui2.Label;
|
|||||||
import com.googlecode.lanterna.gui2.LayoutData;
|
import com.googlecode.lanterna.gui2.LayoutData;
|
||||||
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 xyz.thastertyn.Types.Choice;
|
import xyz.thastertyn.Types.Choice;
|
||||||
import xyz.thastertyn.Types.Predmet;
|
import xyz.thastertyn.Types.Predmet;
|
||||||
import xyz.thastertyn.Types.Znamka;
|
import xyz.thastertyn.Types.Znamka;
|
||||||
import xyz.thastertyn.UserInterface.UpdateListener;
|
import xyz.thastertyn.UserInterface.UpdateListener;
|
||||||
import xyz.thastertyn.UserInterface.Dialogs.OptionsDialog;
|
|
||||||
|
|
||||||
public class Znamky extends JecnaContent {
|
public class Znamky extends JecnaContent {
|
||||||
|
|
||||||
@ -53,6 +51,7 @@ public class Znamky extends JecnaContent {
|
|||||||
{
|
{
|
||||||
super.mainPanel = this.mainPanel;
|
super.mainPanel = this.mainPanel;
|
||||||
super.borderLabel = this.borderLabel;
|
super.borderLabel = this.borderLabel;
|
||||||
|
super.scraper = this.znamky;
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,11 +67,11 @@ public class Znamky extends JecnaContent {
|
|||||||
znamky = new xyz.thastertyn.Scrape.Znamky();
|
znamky = new xyz.thastertyn.Scrape.Znamky();
|
||||||
if(choice != null)
|
if(choice != null)
|
||||||
{
|
{
|
||||||
znamky.downloadZnamky(choice);
|
znamky.download(choice);
|
||||||
setGUI();
|
setGUI();
|
||||||
listener.updatePanel();
|
listener.updatePanel();
|
||||||
}else{
|
}else{
|
||||||
znamky.downloadZnamky();
|
znamky.download();
|
||||||
setGUI();
|
setGUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,16 +147,4 @@ public class Znamky extends JecnaContent {
|
|||||||
vysledneZnamky.addComponent(vysl);
|
vysledneZnamky.addComponent(vysl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void showOptions(WindowBasedTextGUI textGUI) throws IOException {
|
|
||||||
OptionsDialog d = new OptionsDialog(znamky.getOptions());
|
|
||||||
|
|
||||||
Choice c = d.showDialog(textGUI);
|
|
||||||
|
|
||||||
if(c != null)
|
|
||||||
{
|
|
||||||
download(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -3,7 +3,7 @@ package xyz.thastertyn.UserInterface.Dialogs;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import com.googlecode.lanterna.gui2.Button;
|
import com.googlecode.lanterna.gui2.Button;
|
||||||
import com.googlecode.lanterna.gui2.ComboBox;
|
import com.googlecode.lanterna.gui2.ComboBox;
|
||||||
@ -94,7 +94,8 @@ public class OptionsDialog extends DialogWindow {
|
|||||||
// User pressed Ok
|
// User pressed Ok
|
||||||
new Choice(boxs.stream()
|
new Choice(boxs.stream()
|
||||||
.map(box -> box.getSelectedItem().getValue())
|
.map(box -> box.getSelectedItem().getValue())
|
||||||
.toList())
|
.collect(Collectors.toList()))
|
||||||
|
// Why did .toList() stop working?
|
||||||
:
|
:
|
||||||
// User pressed Cancel
|
// User pressed Cancel
|
||||||
null;
|
null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user