Choices are spreading and almost done

This commit is contained in:
Thastertyn 2023-05-03 15:01:57 +02:00
parent 447561c95c
commit 25609a8822
12 changed files with 129 additions and 163 deletions

View File

@ -55,19 +55,19 @@ public class LoginController {
MessageDialogButton.Abort); MessageDialogButton.Abort);
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
MessageDialog.showMessageDialog(textGUI, "No Internet connection", MessageDialog.showMessageDialog(textGUI, "No Internet connection",
"There seems to be a problem with your internet connection", e.getMessage(),
MessageDialogButton.OK); MessageDialogButton.OK);
login(); login();
} catch (CredentialException e) } catch (CredentialException e)
{ {
MessageDialog.showMessageDialog(textGUI, "Incorrect username or password", MessageDialog.showMessageDialog(textGUI, "Incorrect username or password",
"The username or password you entered is incorrect", e.getMessage(),
MessageDialogButton.OK); MessageDialogButton.OK);
login(); login();
} catch (IOException e) } catch (IOException e)
{ {
MessageDialog.showMessageDialog(textGUI, "There was an error", MessageDialog.showMessageDialog(textGUI, "There was an error",
"Maybe try again and it will go away", e.getMessage(),
MessageDialogButton.Retry); MessageDialogButton.Retry);
login(); login();
} }

View File

@ -9,19 +9,16 @@ public class Jidelna extends JecnaScrape {
@Override @Override
public Options[] getOptions() { public Options[] getOptions() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getOptions'"); throw new UnsupportedOperationException("Unimplemented method 'getOptions'");
} }
@Override @Override
public void download(Choice choice) throws IOException { public void download(Choice choice) throws IOException {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'download'"); throw new UnsupportedOperationException("Unimplemented method 'download'");
} }
@Override @Override
public void download() throws IOException { public void download() throws IOException {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'download'"); throw new UnsupportedOperationException("Unimplemented method 'download'");
} }

View File

@ -9,18 +9,35 @@ import org.jsoup.select.Elements;
import xyz.thastertyn.Tuples.Pair; import xyz.thastertyn.Tuples.Pair;
import xyz.thastertyn.Types.Choice; import xyz.thastertyn.Types.Choice;
import xyz.thastertyn.Types.Option;
import xyz.thastertyn.Types.Options; import xyz.thastertyn.Types.Options;
public class OmluvnyList extends JecnaScrape { public class OmluvnyList extends JecnaScrape {
private ArrayList<Pair<String, String>> data = new ArrayList<>(); private ArrayList<Pair<String, String>> data;
private Options schoolYearOptions;
@Override @Override
public void download() throws IOException public void download() throws IOException
{ {
Document omluvnyListDokumentHTML = Downloader.download("https://www.spsejecna.cz/absence/student").get(); download("https://www.spsejecna.cz/absence/student");
}
Elements omluvneListy = omluvnyListDokumentHTML.select("table.absence-list").select("tr"); @Override
public void download(Choice choice) throws IOException {
download(String.format(
"https://www.spsejecna.cz/absence/student?schoolYearId=%s",
choice.getChoices().get(0)));
}
private void download(String url) throws IOException
{
data = new ArrayList<>();
schoolYearOptions = new Options("Skolni R.");
Document omluvnyListDokumentHTML = Downloader.download(url).get();
Elements omluvneListy = omluvnyListDokumentHTML.select("table.absence-list").select("tbody").select("tr");
for(Element e : omluvneListy) for(Element e : omluvneListy)
{ {
@ -29,6 +46,18 @@ public class OmluvnyList extends JecnaScrape {
data.add(new Pair<String, String>(date, text)); data.add(new Pair<String, String>(date, text));
} }
Elements options = omluvnyListDokumentHTML.select("form.listConfigure").select("select[id=schoolYearId]").select("option");
for(Element e : options)
{
schoolYearOptions.addOption(new Option(e.text(), e.attr("value")));
}
}
@Override
public Options[] getOptions() {
return new Options[] {schoolYearOptions};
} }
public ArrayList<Pair<String, String>> getData() public ArrayList<Pair<String, String>> getData()
@ -42,15 +71,4 @@ public class OmluvnyList extends JecnaScrape {
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'");
}
} }

View File

@ -4,12 +4,14 @@ import java.io.IOException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.regex.Pattern;
import org.jsoup.nodes.Document; 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.Choice;
import xyz.thastertyn.Types.Option;
import xyz.thastertyn.Types.Options; import xyz.thastertyn.Types.Options;
import xyz.thastertyn.Types.Timetable; import xyz.thastertyn.Types.Timetable;
@ -19,6 +21,10 @@ import xyz.thastertyn.Types.Timetable;
public class Rozvrh extends JecnaScrape { public class Rozvrh extends JecnaScrape {
private Timetable timetable; private Timetable timetable;
private Options schoolYearOptions;
private Options timetableOptions;
/** /**
* Stahne rozvrh z www.spsejecna.cz a dale ho zpracuje do formy * Stahne rozvrh z www.spsejecna.cz a dale ho zpracuje do formy
* se kterou da pracovat * se kterou da pracovat
@ -29,8 +35,24 @@ public class Rozvrh extends JecnaScrape {
@Override @Override
public void download() throws IOException public void download() throws IOException
{ {
download("https://www.spsejecna.cz/timetable/class");
}
@Override
public void download(Choice choice) throws IOException {
download(String
.format("https://www.spsejecna.cz/timetable/class?schoolYearId=%s&timetableId=%s",
choice.getChoices().get(0),
choice.getChoices().get(1)));
}
private void download(String url) throws IOException
{
schoolYearOptions = new Options("Skolni R.");
timetableOptions = new Options("Obdobi");
timetable = new Timetable(); timetable = new Timetable();
Document rozvrhDokumentHTML = Downloader.download("https://www.spsejecna.cz/timetable/class").get(); Document rozvrhDokumentHTML = Downloader.download(url).get();
Elements[] radkyRozvrhuHTML = rozvrhDokumentHTML Elements[] radkyRozvrhuHTML = rozvrhDokumentHTML
.select("table.timetable") .select("table.timetable")
@ -53,6 +75,28 @@ public class Rozvrh extends JecnaScrape {
timetable.get(i).set(j, pr); timetable.get(i).set(j, pr);
} }
} }
Element optionsPanel = rozvrhDokumentHTML.selectFirst("form.listConfigure");
Elements schoolYear = optionsPanel.select("select[id=schoolYearId]").select("option");
Elements timetableId = optionsPanel.select("select[id=timetableId]").select("option");
for(Element e : schoolYear)
{
schoolYearOptions.addOption(new Option(e.text(), e.attr("value")));
}
for(Element e : timetableId)
{
String text = Pattern
.compile("(Od .* do .*)")
.matcher(e.text())
.results()
.findFirst()
.map(m -> m.group(1))
.orElse(e.text());
timetableOptions.addOption(new Option(text, e.attr("value")));
}
} }
public Timetable getRozvrh() public Timetable getRozvrh()
@ -71,13 +115,6 @@ public class Rozvrh extends JecnaScrape {
@Override @Override
public Options[] getOptions() { public Options[] getOptions() {
// TODO Auto-generated method stub return new Options[] {schoolYearOptions, timetableOptions};
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'");
} }
} }

View File

@ -49,13 +49,11 @@ public class Sdeleni extends JecnaScrape {
@Override @Override
public Options[] getOptions() { public Options[] getOptions() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getOptions'"); throw new UnsupportedOperationException("Unimplemented method 'getOptions'");
} }
@Override @Override
public void download(Choice choice) throws IOException { public void download(Choice choice) throws IOException {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'download'"); throw new UnsupportedOperationException("Unimplemented method 'download'");
} }
} }

View File

@ -22,8 +22,8 @@ public class Znamky extends JecnaScrape {
private ArrayList<Predmet> predmety; private ArrayList<Predmet> predmety;
// int znaci id roku, boolean jestli je jen prvni nebo i druhe pololeti // int znaci id roku, boolean jestli je jen prvni nebo i druhe pololeti
private Options schoolYearOptions = new Options("Skolni R."); private Options schoolYearOptions;
private Options schoolHalfYearOptions = new Options("Pololeti"); private Options schoolHalfYearOptions;
public void download() throws IOException public void download() throws IOException
{ {
@ -41,6 +41,9 @@ public class Znamky extends JecnaScrape {
private void download(String url) throws IOException private void download(String url) throws IOException
{ {
schoolHalfYearOptions = new Options("Pololeti");
schoolYearOptions = new Options("Skolni R.");
predmety = new ArrayList<>(); predmety = new ArrayList<>();
Document znamkyDokumentHTML = Downloader.download(url).get(); Document znamkyDokumentHTML = Downloader.download(url).get();
@ -100,6 +103,7 @@ public class Znamky extends JecnaScrape {
Elements skolniRoky = optionsPanel.select("select[id=schoolYearId]").select("option"); Elements skolniRoky = optionsPanel.select("select[id=schoolYearId]").select("option");
Elements pololeti = optionsPanel.select("select[id=schoolYearHalfId]").select("option"); Elements pololeti = optionsPanel.select("select[id=schoolYearHalfId]").select("option");
for(Element e : skolniRoky) for(Element e : skolniRoky)
{ {
schoolYearOptions.addOption(new Option(e.text(), e.attr("value"))); schoolYearOptions.addOption(new Option(e.text(), e.attr("value")));

View File

@ -40,6 +40,7 @@ public abstract class JecnaContent {
}else{ }else{
scraper.download(); scraper.download();
setGUI(); setGUI();
listener.updatePanel();
} }
hasStarted = true; hasStarted = true;

View File

@ -1,81 +1,42 @@
package xyz.thastertyn.UserInterface.Content; package xyz.thastertyn.UserInterface.Content;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import com.googlecode.lanterna.gui2.Direction;
import com.googlecode.lanterna.gui2.GridLayout;
import com.googlecode.lanterna.gui2.Label; import com.googlecode.lanterna.gui2.Label;
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.Tuples.Pair; import xyz.thastertyn.Tuples.Pair;
import xyz.thastertyn.Types.Choice;
import xyz.thastertyn.UserInterface.UpdateListener; import xyz.thastertyn.UserInterface.UpdateListener;
public class OmluvnyList extends JecnaContent{ public class OmluvnyList extends JecnaContent{
private Panel omluvnyPanel = new Panel();
private Label borderLabel = new Label("Omluvny L.");
private xyz.thastertyn.Scrape.OmluvnyList omluvnyList = new xyz.thastertyn.Scrape.OmluvnyList(); private xyz.thastertyn.Scrape.OmluvnyList omluvnyList = new xyz.thastertyn.Scrape.OmluvnyList();
private boolean hasStarted = false;
public OmluvnyList(UpdateListener listener) public OmluvnyList(UpdateListener listener)
{ {
super(listener); super(listener);
} this.mainPanel = new Panel()
.setLayoutManager(new GridLayout(1));
@Override this.borderLabel = new Label("Omluvny L.");
public void downloadDefault() throws IOException super.scraper = omluvnyList;
{
download(null);
}
@Override
protected void download(Choice choice) throws IOException
{
omluvnyList = new xyz.thastertyn.Scrape.OmluvnyList();
if(choice != null)
{
omluvnyList.download(choice);
setGUI();
listener.updatePanel();
}else{
omluvnyList.download();
setGUI();
}
super.hasStarted = true;
} }
@Override @Override
protected void setGUI() protected void setGUI()
{ {
this.mainPanel.removeAllComponents();
ArrayList<Pair<String, String>> a = omluvnyList.getData(); ArrayList<Pair<String, String>> a = omluvnyList.getData();
Panel content = new Panel()
.setLayoutManager(new LinearLayout(Direction.VERTICAL))
.addTo(mainPanel);
for(Pair<String, String> p : a) for(Pair<String, String> p : a)
{ {
omluvnyPanel.addComponent(new Label(p.getValue0() + " - " + p.getValue1())); content.addComponent(new Label(p.getValue0() + " - " + p.getValue1()));
} }
} }
@Override
public Panel getPanel() {
return omluvnyPanel;
}
@Override
public boolean hasStarted() {
return hasStarted;
}
@Override
public Label getLabel() {
return borderLabel;
}
@Override
public void showOptions(WindowBasedTextGUI textGUI) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getOptions'");
}
} }

View File

@ -1,6 +1,5 @@
package xyz.thastertyn.UserInterface.Content; package xyz.thastertyn.UserInterface.Content;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -8,14 +7,11 @@ import com.googlecode.lanterna.gui2.Label;
import com.googlecode.lanterna.gui2.Panel; import com.googlecode.lanterna.gui2.Panel;
import com.googlecode.lanterna.gui2.table.Table; import com.googlecode.lanterna.gui2.table.Table;
import xyz.thastertyn.Types.Choice;
import xyz.thastertyn.Types.Timetable; import xyz.thastertyn.Types.Timetable;
import xyz.thastertyn.UserInterface.UpdateListener; import xyz.thastertyn.UserInterface.UpdateListener;
public class Rozvrh extends JecnaContent { public class Rozvrh extends JecnaContent {
private Panel rozvrhPanel = new Panel();
private Label borderLabel = new Label("Rozvrh");
private xyz.thastertyn.Scrape.Rozvrh rozvrh = new xyz.thastertyn.Scrape.Rozvrh(); private xyz.thastertyn.Scrape.Rozvrh rozvrh = new xyz.thastertyn.Scrape.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", "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"};
@ -23,35 +19,21 @@ public class Rozvrh extends JecnaContent {
String[] daysLabels = {"PO", "UT", "ST", "CT", "PA"}; String[] daysLabels = {"PO", "UT", "ST", "CT", "PA"};
Table<String> table = new Table<>(labels); Table<String> table;
public Rozvrh(UpdateListener listener) public Rozvrh(UpdateListener listener)
{ {
super(listener); super(listener);
super.mainPanel = this.mainPanel; this.mainPanel = new Panel();
super.borderLabel = this.borderLabel; this.borderLabel = new Label("Rozvrh");
super.scraper = this.rozvrh; super.scraper = this.rozvrh;
} }
@Override
protected void download(Choice choice) throws IOException
{
if(choice != null)
{
scraper.download(choice);
setGUI();
listener.updatePanel();
}else{
scraper.download();
setGUI();
}
hasStarted = true;
}
@Override @Override
protected void setGUI() protected void setGUI()
{ {
mainPanel.removeAllComponents();
table = new Table<>(labels);
Timetable timetable = rozvrh.getRozvrh(); Timetable timetable = rozvrh.getRozvrh();
for(int day = 0; day < 5; day++) for(int day = 0; day < 5; day++)
@ -72,6 +54,6 @@ public class Rozvrh extends JecnaContent {
table.getTableModel().addRow(currentRow); table.getTableModel().addRow(currentRow);
} }
rozvrhPanel.addComponent(table); mainPanel.addComponent(table);
} }
} }

View File

@ -1,63 +1,34 @@
package xyz.thastertyn.UserInterface.Content; package xyz.thastertyn.UserInterface.Content;
import java.io.IOException;
import java.util.ArrayList; 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 xyz.thastertyn.Types.Choice;
import xyz.thastertyn.UserInterface.UpdateListener; import xyz.thastertyn.UserInterface.UpdateListener;
public class Sdeleni extends JecnaContent { public class Sdeleni extends JecnaContent {
private Panel sdeleniPanel = new Panel();
private Label borderLabel = new Label("Sdeleni R.");
private xyz.thastertyn.Scrape.Sdeleni sdeleni = new xyz.thastertyn.Scrape.Sdeleni(); private xyz.thastertyn.Scrape.Sdeleni sdeleni = new xyz.thastertyn.Scrape.Sdeleni();
public Sdeleni(UpdateListener listener) public Sdeleni(UpdateListener listener)
{ {
super(listener); super(listener);
super.mainPanel = this.mainPanel; this.mainPanel = new Panel().setLayoutManager(new GridLayout(1)
super.borderLabel = this.borderLabel; .setLeftMarginSize(1)
.setRightMarginSize(1));
this.borderLabel = new Label("Sdeleni R.");
super.scraper = this.sdeleni; super.scraper = this.sdeleni;
} }
@Override
public void downloadDefault() throws IOException
{
download(null);
}
@Override
protected void download(Choice choice) throws IOException
{
sdeleni = new xyz.thastertyn.Scrape.Sdeleni();
if(choice != null)
{
sdeleni.download(choice);
setGUI();
listener.updatePanel();
}else{
sdeleni.download();
setGUI();
}
super.hasStarted = true;
}
@Override @Override
protected void setGUI() protected void setGUI()
{ {
sdeleniPanel.setLayoutManager(new GridLayout(1) mainPanel.removeAllComponents();
.setLeftMarginSize(1)
.setRightMarginSize(1));
ArrayList<String> sdeleniList = sdeleni.getSdeleni(); ArrayList<String> sdeleniList = sdeleni.getSdeleni();
sdeleniList.forEach(s -> sdeleniPanel.addComponent(new Label(s))); sdeleniList.forEach(sdeleni -> mainPanel.addComponent(new Label(sdeleni)));
} }
} }

View File

@ -38,18 +38,15 @@ public class Znamky extends JecnaContent {
true, true,
false); false);
private Panel mainPanel = new Panel()
.setLayoutManager(new GridLayout(3));
private Label borderLabel = new Label("Znamky");
private xyz.thastertyn.Scrape.Znamky znamky = new xyz.thastertyn.Scrape.Znamky(); private xyz.thastertyn.Scrape.Znamky znamky = new xyz.thastertyn.Scrape.Znamky();
public Znamky(UpdateListener listener) public Znamky(UpdateListener listener)
{ {
super(listener); super(listener);
super.mainPanel = this.mainPanel;
super.borderLabel = this.borderLabel; this.mainPanel = new Panel()
.setLayoutManager(new GridLayout(3));
this.borderLabel = new Label("Znamky");
super.scraper = this.znamky; super.scraper = this.znamky;
} }

View File

@ -29,8 +29,8 @@ public class WindowSwitchListener implements WindowListener, UpdateListener {
private WindowBasedTextGUI textGUI; private WindowBasedTextGUI textGUI;
private JecnaContent[] contents = { private JecnaContent[] contents = {
new Znamky(this),
new Rozvrh(this), new Rozvrh(this),
new Znamky(this), // This being first doesn't resize properly for some reason
new Sdeleni(this), new Sdeleni(this),
new OmluvnyList(this) new OmluvnyList(this)
}; };
@ -99,7 +99,7 @@ public class WindowSwitchListener implements WindowListener, UpdateListener {
contents[current].downloadDefault(); contents[current].downloadDefault();
}catch(IOException e) }catch(IOException e)
{ {
MessageDialog.showMessageDialog(textGUI, "Something failed", "The content failed to download", MessageDialogButton.OK); MessageDialog.showMessageDialog(textGUI, "Something failed", e.getMessage(), MessageDialogButton.OK);
} }
} }
} }
@ -110,20 +110,21 @@ public class WindowSwitchListener implements WindowListener, UpdateListener {
.getSize() .getSize()
.getColumns(); .getColumns();
int currentSize = contents[current] int currentColumns = contents[current]
.getPanel() .getPanel()
.getSize() .getSize()
.getColumns(); .getColumns();
if(currentSize < tabColumns) if(currentColumns < tabColumns)
{ {
holderPanel.addComponent( holderPanel.addComponent(
contents[current].getPanel().setPreferredSize(new TerminalSize(tabColumns, contents[current].getPanel().setPreferredSize(new TerminalSize(
tabColumns - 2,
contents[current].getPanel().getPreferredSize().getRows()))); contents[current].getPanel().getPreferredSize().getRows())));
return;
}else{
holderPanel.addComponent(contents[current].getPanel());
} }
holderPanel.addComponent(contents[current].getPanel());
} }
private void updateLabels() private void updateLabels()
@ -180,7 +181,6 @@ public class WindowSwitchListener implements WindowListener, UpdateListener {
@Override @Override
public void onUnhandledInput(Window basePane, KeyStroke keyStroke, AtomicBoolean hasBeenHandled) { public void onUnhandledInput(Window basePane, KeyStroke keyStroke, AtomicBoolean hasBeenHandled) {
// TODO Auto-generated method stub
} }
@Override @Override
@ -190,12 +190,12 @@ public class WindowSwitchListener implements WindowListener, UpdateListener {
@Override @Override
public void onMoved(Window window, TerminalPosition oldPosition, TerminalPosition newPosition) { public void onMoved(Window window, TerminalPosition oldPosition, TerminalPosition newPosition) {
// TODO Auto-generated method stub
} }
@Override @Override
public void updatePanel() { public void updatePanel() {
holderPanel.removeAllComponents(); holderPanel.removeAllComponents();
// Todo find a way to resize the panel on screen
holderPanel.addComponent(contents[current].getPanel()); holderPanel.addComponent(contents[current].getPanel());
} }