Tabs, rozvrh + znamky tabs
This commit is contained in:
1 parent
4464cd2840
commit
3a37456337
37 files changed
+660
-345
No files matched your search
@@ -3,9 +3,9 @@ package xyz.thastertyn.Jecna;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
|
||||
import xyz.thastertyn.Connection;
|
||||
import xyz.thastertyn.Tuple.Pair;
|
||||
|
||||
public class Dochazka {
|
||||
@@ -18,9 +18,10 @@ public class Dochazka {
|
||||
|
||||
try {
|
||||
// absence-list
|
||||
absenceDoc = Connection.getConnection()
|
||||
absenceDoc = Jsoup.connect("https://www.spsejecna.cz" + "/absence/passing-student")
|
||||
.cookie("JSESSIOND", JSESSIOND)
|
||||
.url("https://www.spsejecna.cz" + "/absence/passing-student")
|
||||
.cookie("role", "student")
|
||||
.header("Connection", "keep-alive")
|
||||
.get();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package xyz.thastertyn.Jecna;
|
||||
|
||||
public class Jidelna {
|
||||
|
||||
}
|
||||
@@ -4,9 +4,12 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import javax.security.auth.login.CredentialException;
|
||||
|
||||
import org.jsoup.Connection;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.Connection.Method;
|
||||
import org.jsoup.nodes.Document;
|
||||
|
||||
public class Login {
|
||||
|
||||
@@ -23,7 +26,7 @@ public class Login {
|
||||
* <li> {@code false} neexistuje, nebo jsou prazdne </li>
|
||||
* </ul>
|
||||
*/
|
||||
public boolean getCredentials()
|
||||
public boolean checkForCredentials()
|
||||
{
|
||||
File credentials = null;
|
||||
|
||||
@@ -67,9 +70,8 @@ public class Login {
|
||||
return Jsessionid;
|
||||
}
|
||||
|
||||
public byte login(String user, String pass)
|
||||
public void loginJecna(String user, String pass) throws UnknownHostException, IOException, CredentialException
|
||||
{
|
||||
try {
|
||||
//#region JSESSIONID
|
||||
Connection.Response response = Jsoup.connect("https://www.spsejecna.cz")
|
||||
.header("Connection", "keep-alive")
|
||||
@@ -89,7 +91,7 @@ public class Login {
|
||||
//#endregion
|
||||
|
||||
//#region Login
|
||||
Connection.Response login = Jsoup.connect("https://www.spsejecna.cz/user/login")
|
||||
Jsoup.connect("https://www.spsejecna.cz/user/login")
|
||||
.method(Connection.Method.POST)
|
||||
.header("Content-Type", "application/x-www-form-urlencoded")
|
||||
//.header("Content-Length", "71") Adds 10 seconds to total request time
|
||||
@@ -105,17 +107,63 @@ public class Login {
|
||||
.execute();
|
||||
//#endregion
|
||||
|
||||
Document test = Jsoup.connect("https://www.spsejecna.cz/score/student")
|
||||
.header("Connection", "keep-alive")
|
||||
.cookie("JSESSIONID", Jsessionid)
|
||||
.cookie("role", "student")
|
||||
.get();
|
||||
|
||||
if(test.toString().contains("Pro pokračování se přihlaste do systému"))
|
||||
{
|
||||
throw new CredentialException("Incorrect username or password");
|
||||
}
|
||||
|
||||
start = System.currentTimeMillis() / 1000L;
|
||||
lastCheck = start;
|
||||
}
|
||||
|
||||
return 0;
|
||||
} catch(UnknownHostException e)
|
||||
{
|
||||
// Not connected to internet
|
||||
return 127;
|
||||
} catch(IOException e)
|
||||
{
|
||||
return 126;
|
||||
}
|
||||
public void loginJidelna() throws UnknownHostException, IOException
|
||||
{
|
||||
//#region JSESSIONID
|
||||
Connection.Response jidelna = Jsoup.connect("https://objednavky.jidelnasokolska.cz/")
|
||||
.header("Connection", "keep-alive")
|
||||
.method(Method.HEAD)
|
||||
.execute();
|
||||
|
||||
String jidelnaJSESSIONID = jidelna.cookie("JSESSIONID");
|
||||
String XSRF_TOKEN = jidelna.cookie("XSRF-TOKEN");
|
||||
//#endregion
|
||||
|
||||
//#region CSRF
|
||||
String csrf = Jsoup.connect("https://objednavky.jidelnasokolska.cz/faces/login.jsp")
|
||||
.header("Connection", "keep-alive")
|
||||
.cookie("XSRF-TOKEN", XSRF_TOKEN)
|
||||
.cookie("JSESSIONID", jidelnaJSESSIONID)
|
||||
.get()
|
||||
.select("input[name=_csrf]")
|
||||
.attr("value");
|
||||
|
||||
|
||||
if(!XSRF_TOKEN.equals(csrf))
|
||||
{
|
||||
throw new SecurityException("CSRF tokens do not match, something is up");
|
||||
}
|
||||
//#endregion
|
||||
|
||||
//#region Login
|
||||
Connection.Response jidelnaLogin = 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("terminal", "false")
|
||||
.data("type", "web")
|
||||
.data("_csrf", XSRF_TOKEN)
|
||||
.data("targetUrl", "/faces/secured/main.jsp?terminal=false&status=true&printer=false&keyboard=false")
|
||||
.method(Method.POST)
|
||||
.execute();
|
||||
//#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
package xyz.thastertyn.Jecna;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
@@ -15,17 +16,20 @@ public class Znamky {
|
||||
|
||||
private boolean wasDownloaded;
|
||||
|
||||
// key (String) reprezentuje predmet, value (arraylist) znamky a pair znamku s jeji vahou
|
||||
private HashMap<String, ArrayList<Pair<Integer, Double>>> grades = new HashMap<>();
|
||||
private ArrayList<Pair<String, Pair<ArrayList<Pair<Integer, Double>>,Double>>> grades = new ArrayList<>();
|
||||
|
||||
public void addGrade(String subject, int grade, double weight)
|
||||
public void addGrade(int index, String subject, int grade, double weight)
|
||||
{
|
||||
grades.get(subject).add(new Pair<Integer,Double>(grade, weight));
|
||||
Pair<Integer, Double> znamka = new Pair<>(grade, weight);
|
||||
|
||||
grades.get(index).getValue1().getValue0().add(znamka);
|
||||
}
|
||||
|
||||
public void addSubject(String subject)
|
||||
{
|
||||
grades.put(subject, new ArrayList<Pair<Integer, Double>>());
|
||||
Pair<ArrayList<Pair<Integer, Double>>, Double> p = new Pair<>(new ArrayList<Pair<Integer, Double>>(), 0.0);
|
||||
|
||||
grades.add(new Pair<>(subject, p));
|
||||
}
|
||||
|
||||
private double getAverage(ArrayList<Pair<Integer, Double>> a)
|
||||
@@ -39,7 +43,8 @@ public class Znamky {
|
||||
divisor += p.getValue1();
|
||||
}
|
||||
|
||||
return (double) divident / divisor;
|
||||
double prumer = (double) divident / divisor;
|
||||
return (double) Math.round(prumer * 100) / 100;
|
||||
|
||||
}catch(ArithmeticException e)
|
||||
{
|
||||
@@ -47,17 +52,10 @@ public class Znamky {
|
||||
}
|
||||
}
|
||||
|
||||
public byte downloadZnamky(final String Jsessionid)
|
||||
public void downloadZnamky(final String Jsessionid) throws UnknownHostException, IOException
|
||||
{
|
||||
wasDownloaded = true;
|
||||
Document znamkyDoc = null;
|
||||
|
||||
try {
|
||||
znamkyDoc = Downloader.download("https://www.spsejecna.cz" + "/score/student", Jsessionid).get();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return 127;
|
||||
}
|
||||
Document znamkyDoc = Downloader.download("https://www.spsejecna.cz" + "/score/student", Jsessionid).get();
|
||||
|
||||
Elements rows = znamkyDoc.select("table.score").select("tr");
|
||||
|
||||
@@ -68,25 +66,43 @@ public class Znamky {
|
||||
rows_split[i] = rows.get(i).children();
|
||||
}
|
||||
|
||||
int subj = 0;
|
||||
|
||||
for(int i = 1; i < rows_split.length; i++)
|
||||
{
|
||||
String predmet = rows_split[i].get(0).text();
|
||||
String predmetFull = rows_split[i].get(0).text();
|
||||
|
||||
Matcher matcher = Pattern.compile("\\((.*)\\)").matcher(predmetFull);
|
||||
|
||||
String predmet = matcher.find() ? matcher.group(1) : predmetFull;
|
||||
addSubject(predmet);
|
||||
|
||||
for(Element e : rows_split[i].get(1).select("a.score"))
|
||||
for(Element znamkaElement : rows_split[i].get(1).select("a.score"))
|
||||
{
|
||||
int znamka = Integer.parseInt(e.select("span.value").text());
|
||||
if(znamkaElement == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
int znamka = Integer.parseInt(znamkaElement.select("span.value").text());
|
||||
|
||||
// Mala znamka se bude pocitat jako polovicni vaha
|
||||
if(e.hasClass("scoreSmall"))
|
||||
if(znamkaElement.hasClass("scoreSmall"))
|
||||
{
|
||||
addGrade(predmet, znamka, 0.5);
|
||||
addGrade(subj, predmet, znamka, 0.5);
|
||||
}else{
|
||||
addGrade(predmet, znamka, 1);
|
||||
addGrade(subj, predmet, znamka, 1);
|
||||
}
|
||||
}
|
||||
|
||||
grades.get(subj).getValue1().setValue1(getAverage(grades.get(subj).getValue1().getValue0()));
|
||||
subj++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public ArrayList<Pair<String, Pair<ArrayList<Pair<Integer, Double>>,Double>>> getGrades()
|
||||
{
|
||||
return grades;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -96,11 +112,9 @@ public class Znamky {
|
||||
{
|
||||
String s = "";
|
||||
|
||||
for(Map.Entry<String, ArrayList<Pair<Integer, Double>>> entry : grades.entrySet())
|
||||
for(Pair<String, Pair<ArrayList<Pair<Integer, Double>>,Double>> p : grades)
|
||||
{
|
||||
double prumer = getAverage(entry.getValue());
|
||||
double p = (double) Math.round(prumer * 100) / 100;
|
||||
s += entry.getKey() + " | " + entry.getValue().toString() + " { " + p + " }\n";
|
||||
s += p.getValue0() + " | " + p.getValue1().getValue0().toString() + " { " + p.getValue1().getValue1() + " } ";
|
||||
}
|
||||
return s;
|
||||
}else{
|
||||
|
||||
Reference in new issue
Block a user