wip access to marks
This commit is contained in:
parent
7855129daf
commit
eeb369cb50
1 changed files with 23 additions and 22 deletions
45
main.py
45
main.py
|
@ -1,8 +1,9 @@
|
||||||
|
from difflib import restore
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from os import environ
|
from os import environ
|
||||||
from sys import argv
|
from sys import argv
|
||||||
|
|
||||||
from requests_html import BaseSession
|
from requests_html import HTMLSession
|
||||||
|
|
||||||
class Universite:
|
class Universite:
|
||||||
def __init__(self, url: str, pseudo: str, motDePasse: str):
|
def __init__(self, url: str, pseudo: str, motDePasse: str):
|
||||||
|
@ -14,14 +15,14 @@ class Universite:
|
||||||
"submit": "SE CONNECTER"
|
"submit": "SE CONNECTER"
|
||||||
}
|
}
|
||||||
|
|
||||||
def ecrirePageHTML(self, texte: str):
|
def ecrirePageHTML(self, nom: str, texte: str):
|
||||||
"""Affiche la page HTML pour le debug."""
|
"""Affiche la page HTML pour le debug."""
|
||||||
with open("page.html", 'w') as f:
|
with open(f"{nom}.html", 'w') as f:
|
||||||
f.write(texte)
|
f.write(texte)
|
||||||
|
|
||||||
def recuperationNotes(self) -> dict:
|
def recuperationNotes(self) -> dict:
|
||||||
"""Récupère les notes sous forme d'un dictionnaire."""
|
"""Récupère les notes sous forme d'un dictionnaire."""
|
||||||
with BaseSession() as session:
|
with HTMLSession() as session:
|
||||||
reponse = session.get(self.url)
|
reponse = session.get(self.url)
|
||||||
|
|
||||||
# login
|
# login
|
||||||
|
@ -41,28 +42,28 @@ class Universite:
|
||||||
# choix des années
|
# choix des années
|
||||||
url = f"{url}?{[element.attrs['action'] for element in reponse.html.find('form') if 'enctype' in element.attrs if element.attrs['enctype'] == 'application/x-www-form-urlencoded'][0].split('?')[1].replace('welcome', 'notes')}"
|
url = f"{url}?{[element.attrs['action'] for element in reponse.html.find('form') if 'enctype' in element.attrs if element.attrs['enctype'] == 'application/x-www-form-urlencoded'][0].split('?')[1].replace('welcome', 'notes')}"
|
||||||
reponse = session.get(url)
|
reponse = session.get(url)
|
||||||
|
anneesTemp = [element for element in reponse.html.find('a') if "href" in element.attrs if element.attrs["href"] == '#'][6:]
|
||||||
|
# on retire un item sur deux car : ['L2MINF/210', 'L2 Informatique', 'L1MINF/210', 'L1 Informatique'] il y a des doublons
|
||||||
|
annees = []
|
||||||
|
for i in range(0, len(anneesTemp)):
|
||||||
|
if i % 2:
|
||||||
|
annees.append(anneesTemp[i])
|
||||||
|
|
||||||
# page des notes
|
# récupération notes
|
||||||
# TODO
|
resultat = {}
|
||||||
|
for annee in annees:
|
||||||
|
reponse = session.post(url)
|
||||||
|
script = annee.attrs['onclick'][7:]
|
||||||
|
reponse.html.render(script=script)
|
||||||
|
resultat[annee.text] = None
|
||||||
|
|
||||||
return self.stringVersDictNotes(reponse.text)
|
url = url.replace("notes", "detailnotes")
|
||||||
|
reponse = session.get(url)
|
||||||
|
url = url.replace("detailnotes", "notes")
|
||||||
|
self.ecrirePageHTML(annee.text, reponse.text)
|
||||||
|
|
||||||
def stringVersDictNotes(self, html: str) -> dict:
|
|
||||||
"""Récupère la page HTML contenant les notes et renvoie un dictionnaire."""
|
|
||||||
self.ecrirePageHTML(html)
|
|
||||||
|
|
||||||
# récupération tableaux des notes
|
return resultat
|
||||||
""" soup = self.maSoupe(reponse)
|
|
||||||
for attrs in soup.findAll("table"):
|
|
||||||
try:
|
|
||||||
texte = str(attrs).split("thead")[1][2:-2]
|
|
||||||
while " " in texte:
|
|
||||||
texte = texte.replace(" ", ' ')
|
|
||||||
return texte
|
|
||||||
except:
|
|
||||||
pass """
|
|
||||||
|
|
||||||
return {"WIP": None}
|
|
||||||
|
|
||||||
def affichageNotes(self, notes: dict) -> str:
|
def affichageNotes(self, notes: dict) -> str:
|
||||||
"""Renvoie un jolie tableau avec les notes"""
|
"""Renvoie un jolie tableau avec les notes"""
|
||||||
|
|
Reference in a new issue