Adding a skeleton
This commit is contained in:
parent
eb4a5d414d
commit
081402832b
1 changed files with 30 additions and 16 deletions
46
main.py
46
main.py
|
@ -19,8 +19,8 @@ class Universite:
|
||||||
with open("page.html", 'w') as f:
|
with open("page.html", 'w') as f:
|
||||||
f.write(texte)
|
f.write(texte)
|
||||||
|
|
||||||
def recuperationNotes(self) -> str:
|
def recuperationNotes(self) -> dict:
|
||||||
"""Récupère les notes."""
|
"""Récupère les notes sous forme d'un dictionnaire."""
|
||||||
with BaseSession() as session:
|
with BaseSession() as session:
|
||||||
reponse = session.get(self.url)
|
reponse = session.get(self.url)
|
||||||
|
|
||||||
|
@ -41,31 +41,45 @@ 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)
|
||||||
self.ecrirePageHTML(reponse.text)
|
|
||||||
|
|
||||||
# page des notes
|
# page des notes
|
||||||
# TODO
|
# TODO
|
||||||
|
|
||||||
# récupération tableaux des notes
|
return self.stringVersDictNotes(reponse.text)
|
||||||
""" soup = self.maSoupe(reponse)
|
|
||||||
for attrs in soup.findAll("table"):
|
def stringVersDictNotes(self, html: str) -> dict:
|
||||||
try:
|
"""Récupère la page HTML contenant les notes et renvoie un dictionnaire."""
|
||||||
texte = str(attrs).split("thead")[1][2:-2]
|
self.ecrirePageHTML(html)
|
||||||
while " " in texte:
|
|
||||||
texte = texte.replace(" ", ' ')
|
# récupération tableaux des notes
|
||||||
return texte
|
""" soup = self.maSoupe(reponse)
|
||||||
except:
|
for attrs in soup.findAll("table"):
|
||||||
pass """
|
try:
|
||||||
return "WIP"
|
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:
|
||||||
|
"""Renvoie un jolie tableau avec les notes"""
|
||||||
|
return str(notes)
|
||||||
|
|
||||||
|
def notes(self):
|
||||||
|
"""Affiche les notes dans stdout."""
|
||||||
|
print(self.affichageNotes(self.recuperationNotes()))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
nom = argv.pop(0)
|
nom = argv.pop(0)
|
||||||
if len(argv) == 3:
|
if len(argv) == 3:
|
||||||
print(Universite(*argv).recuperationNotes())
|
Universite(*argv).notes()
|
||||||
else:
|
else:
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
try:
|
try:
|
||||||
print(Universite(environ["URL"], environ["LOGIN"], environ["PASSWORD"]).recuperationNotes())
|
Universite(environ["URL"], environ["LOGIN"], environ["PASSWORD"]).notes()
|
||||||
except:
|
except:
|
||||||
print(f"""Merci de renseigner l'URL, le pseudo et le mot de passe (avec des \"). \
|
print(f"""Merci de renseigner l'URL, le pseudo et le mot de passe (avec des \"). \
|
||||||
\n-> python3 {nom} "URL" "pseudo" "mot-de-passe" \
|
\n-> python3 {nom} "URL" "pseudo" "mot-de-passe" \
|
||||||
|
|
Reference in a new issue