Browse Source

cadeau

master
Astequ 1 year ago
parent
commit
c6b0ea9485
15 changed files with 606 additions and 0 deletions
  1. +4
    -0
      .idea/encodings.xml
  2. +30
    -0
      .idea/libraries/net_sourceforge_htmlunit_htmlunit_2_15.xml
  3. +10
    -0
      .idea/libraries/org_jsoup_jsoup_1_11_3.xml
  4. +6
    -0
      .idea/misc.xml
  5. +8
    -0
      .idea/modules.xml
  6. +124
    -0
      .idea/uiDesigner.xml
  7. +6
    -0
      .idea/vcs.xml
  8. +13
    -0
      lnascrap.iml
  9. +22
    -0
      src/main/Main.java
  10. +88
    -0
      src/pojo/Matiere.java
  11. +59
    -0
      src/pojo/Note.java
  12. +59
    -0
      src/pojo/Releve.java
  13. +92
    -0
      src/pojo/UE.java
  14. +42
    -0
      src/scrapper/Parser.java
  15. +43
    -0
      src/scrapper/Scrap.java

+ 4
- 0
.idea/encodings.xml View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
</project>

+ 30
- 0
.idea/libraries/net_sourceforge_htmlunit_htmlunit_2_15.xml View File

@@ -0,0 +1,30 @@
<component name="libraryTable">
<library name="net.sourceforge.htmlunit:htmlunit:2.15" type="repository">
<properties maven-id="net.sourceforge.htmlunit:htmlunit:2.15" />
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/htmlunit-2.15.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/xalan-2.7.1.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/serializer-2.7.1.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/commons-collections-3.2.1.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/commons-lang3-3.3.2.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/httpclient-4.3.3.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/httpcore-4.3.2.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/httpmime-4.3.3.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/commons-codec-1.9.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/htmlunit-core-js-2.15.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/xercesImpl-2.11.0.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/xml-apis-1.4.01.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/nekohtml-1.9.21.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/cssparser-0.9.14.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/sac-1.3.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/commons-io-2.4.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/commons-logging-1.1.3.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/jetty-websocket-8.1.15.v20140411.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/jetty-util-8.1.15.v20140411.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/jetty-io-8.1.15.v20140411.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/jetty-http-8.1.15.v20140411.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

+ 10
- 0
.idea/libraries/org_jsoup_jsoup_1_11_3.xml View File

@@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="org.jsoup:jsoup:1.11.3" type="repository">
<properties maven-id="org.jsoup:jsoup:1.11.3" />
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/jsoup-1.11.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

+ 6
- 0
.idea/misc.xml View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

+ 8
- 0
.idea/modules.xml View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/lnascrap.iml" filepath="$PROJECT_DIR$/lnascrap.iml" />
</modules>
</component>
</project>

+ 124
- 0
.idea/uiDesigner.xml View File

@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

+ 6
- 0
.idea/vcs.xml View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

+ 13
- 0
lnascrap.iml View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="org.jsoup:jsoup:1.11.3" level="project" />
<orderEntry type="library" name="net.sourceforge.htmlunit:htmlunit:2.15" level="project" />
</component>
</module>

+ 22
- 0
src/main/Main.java View File

@@ -0,0 +1,22 @@
package main;

import pojo.Matiere;
import pojo.Releve;
import pojo.UE;
import scrapper.Parser;
import scrapper.Scrap;

public class Main {
public static void main(String[] args) {
Scrap owo = new Scrap("user", "pass");
owo.login();
Releve uwu = Parser.parsePage(owo.get("https://dptinfo.iutmetz.univ-lorraine.fr/lna/releve/ficherelevenote.php"));

for (UE ue : uwu.getUes()) {
System.out.println(ue.getFullName() + " " + ue.getAverage());
for (Matiere sub : ue.getSubjects())
System.out.println((sub.getAverage() == -1) ? "" : sub.getName() + " " + sub.getAverage());
}
System.out.println(uwu.getAverage());
}
}

+ 88
- 0
src/pojo/Matiere.java View File

@@ -0,0 +1,88 @@
package pojo;

import java.util.ArrayList;

public class Matiere {
private String name;
private String fullName;
private ArrayList<Note> grades;
private double coeff;

public Matiere(String name, String fullName, double coeff) {
this.name = name;
this.fullName = fullName;
this.grades = new ArrayList<>();
this.coeff = coeff;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getFullName() {
return fullName;
}

public void setFullName(String fullName) {
this.fullName = fullName;
}

public ArrayList<Note> getGrades() {
return grades;
}

public void setGrades(ArrayList<Note> grades) {
this.grades = grades;
}

public void addGrade(Note grade) {
this.grades.add(grade);
}

public double getCoeff() {
return coeff;
}

public void setCoeff(double coeff) {
this.coeff = coeff;
}

public double getCoeffSum() {
if (this.grades.isEmpty())
return -1;
double out = 0;
for (Note grade : this.grades) {
out += grade.getCoeff();
}
return Math.round(out * 100) / 100.0;
}

public double getAverage() {
if (this.grades.isEmpty())
return -1;
double out = 0;
for (Note grade : this.grades) {
out += grade.getValue() * grade.getCoeff();
}
return Math.round((out / this.getCoeffSum()) * 100) / 100.0;
}

@Override
public String toString() {
String gradesTxt = "";
if (this.grades != null && !this.grades.isEmpty()) {
for (Note grade : this.grades) gradesTxt = gradesTxt.concat("\n" + grade.toString());
gradesTxt = gradesTxt.substring(1);
}
return "Matiere{" +
"name='" + name + '\'' +
", fullName='" + fullName + '\'' +
", coeff=" + coeff + '\n' +
", grades='" + gradesTxt +
'}';
}
}

+ 59
- 0
src/pojo/Note.java View File

@@ -0,0 +1,59 @@
package pojo;

import java.time.LocalDate;

public class Note {
private String name;
private LocalDate date;
private double value;
private double coeff;

public Note(String name, LocalDate date, double value, double coeff) {
this.name = name;
this.date = date;
this.value = value;
this.coeff = coeff;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public LocalDate getDate() {
return date;
}

public void setDate(LocalDate date) {
this.date = date;
}

public double getValue() {
return value;
}

public void setValue(double value) {
this.value = value;
}

public double getCoeff() {
return coeff;
}

public void setCoeff(double coeff) {
this.coeff = coeff;
}

@Override
public String toString() {
return "Note{" +
"name='" + name + '\'' +
", date=" + date +
", value=" + value +
", coeff=" + coeff +
'}';
}
}

+ 59
- 0
src/pojo/Releve.java View File

@@ -0,0 +1,59 @@
package pojo;

import java.util.ArrayList;

public class Releve {
private ArrayList<UE> ues;

public Releve() {
this.ues = new ArrayList<>();
}

public ArrayList<UE> getUes() {
return ues;
}

public void setUes(ArrayList<UE> ues) {
this.ues = ues;
}

public void addUe(UE ue) {
this.ues.add(ue);
}

public double getCoeffSum() {
if (this.ues.isEmpty())
return -1;
double out = 0;
for (UE ue : this.ues) {
if (ue.getCoeffSum() != -1)
out += ue.getCoeff();
}
return Math.round(out * 100) / 100.0;
}

public double getAverage() {
if (this.ues.isEmpty())
return -1;
double out = -1;
for (UE ue : this.ues) {
if (ue.getAverage() != -1)
out += ue.getAverage() * ue.getCoeff();
}
return (out == -1) ? out : Math.round(((out + 1) / this.getCoeffSum()) * 100) / 100.0;
}

@Override
public String toString() {
String ueTxt = "";
if (!this.ues.isEmpty()) {
for (UE ue : this.ues) {
ueTxt = ueTxt.concat("\n" + ue.toString());
}
ueTxt = ueTxt.substring(1);
}
return "Releve{" +
"ues=\n" + ueTxt +
'}';
}
}

+ 92
- 0
src/pojo/UE.java View File

@@ -0,0 +1,92 @@
package pojo;

import java.util.ArrayList;

public class UE {
private String name;
private String fullName;
private ArrayList<Matiere> subjects;

public UE(String name, String fullName) {
this.name = name;
this.fullName = fullName;
this.subjects = new ArrayList<>();
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getFullName() {
return fullName;
}

public void setFullName(String fullName) {
this.fullName = fullName;
}

public ArrayList<Matiere> getSubjects() {
return subjects;
}

public void setSubjects(ArrayList<Matiere> subjects) {
this.subjects = subjects;
}

public void addSubject(Matiere subject) {
this.subjects.add(subject);
}

public double getCoeffSum() {
if (this.subjects.isEmpty())
return -1;
double out = -1;
for (Matiere subject : this.subjects) {
if (subject.getAverage() != -1)
out += subject.getCoeff();
}
return (out == -1) ? out : Math.round((out + 1) * 100) / 100.0;
}

public double getCoeff() {
if (this.subjects.isEmpty())
return -1;
double out = 0;
for (Matiere subject : this.subjects) {
out += subject.getCoeff();
}
return Math.round(out * 100) / 100.0;
}


public double getAverage() {
if (this.subjects.isEmpty())
return -1;
double out = -1;
for (Matiere subject : this.subjects) {
if (subject.getAverage() != -1)
out += subject.getAverage() * subject.getCoeff();
}
return (out == -1) ? out : Math.round(((out + 1) / this.getCoeffSum()) * 100) / 100.0;
}

@Override
public String toString() {
String subsTxt = "";
if (this.subjects != null && !this.subjects.isEmpty()) {
for (Matiere subject : this.subjects) {
subsTxt = subsTxt.concat("\n" + subject.toString());
}
subsTxt = subsTxt.substring(1);
}
return "UE{" +
"name='" + name + '\'' +
", fullName='" + fullName + '\n' +
", subjects=" + subsTxt +
'}';
}
}

+ 42
- 0
src/scrapper/Parser.java View File

@@ -0,0 +1,42 @@
package scrapper;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import pojo.Matiere;
import pojo.Note;
import pojo.Releve;
import pojo.UE;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class Parser {

public static Releve parsePage(String page) {
Releve out = new Releve();
UE currentUE = null;
Element table = Jsoup.parse(page).select("div.affigauche2>table>tbody").get(1);
Elements ues = table.select("tr");
for (int i = 2; i < ues.size(); i++)
if (ues.get(i).hasClass("ligne_unite")) {
Elements htmlUE = ues.get(i).select("td");
if (currentUE != null)
out.addUe(currentUE);
currentUE = new UE(htmlUE.get(0).text(), htmlUE.get(1).text());
} else if (currentUE != null) {
Elements sub = ues.get(i).select("td");
Matiere currentSub = new Matiere(sub.get(0).text(), sub.get(1).text(), Double.parseDouble(sub.get(3).text().substring(sub.get(3).text().length() - 5, sub.get(3).text().length() - 1)));
currentUE.addSubject(currentSub);
Elements ctrls = ues.get(i).select("td.ligne_controle");
for (Element ctrl : ctrls)
if (!ctrl.text().equals("")) {
String[] noteCell = ctrl.html().split("<br>");
currentSub.addGrade(new Note(noteCell[0], LocalDate.parse(noteCell[1], DateTimeFormatter.ofPattern("dd/MM/yyyy")), Double.parseDouble(Jsoup.parse(noteCell[2]).select("b").text().replace(',', '.')), Double.parseDouble(noteCell[2].split("</b>")[1].trim().substring(1, 5))));
}
}
if (currentUE != null)
out.addUe(currentUE);
return out;
}
}

+ 43
- 0
src/scrapper/Scrap.java View File

@@ -0,0 +1,43 @@
package scrapper;

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;

import java.io.IOException;

public class Scrap {
private WebClient WEB_CLIENT = new WebClient(BrowserVersion.CHROME);
private String user;
private String pass;
private String loginUrl = "https://dptinfo.iutmetz.univ-lorraine.fr/lna/accueil.php";

public Scrap(String user, String pass) {
this.user = user;
this.pass = pass;
WEB_CLIENT.getCookieManager().setCookiesEnabled(true);
}


public void login() {
try {
HtmlPage loginPage = WEB_CLIENT.getPage(this.loginUrl);
HtmlForm loginForm = loginPage.getFirstByXPath("//form[@id='loginForm']");
loginForm.getInputByName("the_login").setValueAttribute(this.user);
loginForm.getInputByName("the_mdp").setValueAttribute(this.pass);
loginForm.getInputByName("Envoyer").click();
} catch (IOException e) {
e.printStackTrace();
}
}

public String get(String url) {
try {
return WEB_CLIENT.getPage(url).getWebResponse().getContentAsString();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}

Loading…
Cancel
Save