use requirements.txt for venv

This commit is contained in:
Mylloon 2023-01-12 22:40:44 +01:00
parent 34b6b0cde1
commit 9e7226db24
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
4 changed files with 29 additions and 18 deletions

4
.gitignore vendored
View file

@ -3,3 +3,7 @@
.env
*.html
bin/
lib/
pyvenv.cfg

View file

@ -1,12 +1,7 @@
# Wrapper de notes pour [uPortal](https://github.com/uPortal-Project/uPortal-start)
## Pré-requis
```
requests-html==0.10.0
python-dotenv==0.19.2
```
## Utilisation
```
python3 main.py "<lien-vers-l'instance-CAS-pour-la-connexion-à-uPortal>" "<pseudo>" "<mot-de-passe>"
@ -16,4 +11,5 @@ python3 main.py "<lien-vers-l'instance-CAS-pour-la-connexion-à-uPortal>" "<pseu
Vous pouvez aussi utilisez un fichier `.env` (recommandé) avec : `URL`, `LOGIN` et `PASSWORD` comme nom de variables.
---
Testé avec l'[instance de Paris 8](https://e-p8.univ-paris8.fr).

27
main.py
View file

@ -1,10 +1,10 @@
from difflib import restore
from dotenv import load_dotenv
from os import environ
from sys import argv
from requests_html import HTMLSession
class Universite:
def __init__(self, url: str, pseudo: str, motDePasse: str):
self.url = url
@ -26,15 +26,19 @@ class Universite:
reponse = session.get(self.url)
# login
self.loginData["lt"] = [element.attrs["value"] for element in reponse.html.find("input") if element.attrs["name"] == "lt"][0]
self.loginData["execution"] = [element.attrs["value"] for element in reponse.html.find("input") if element.attrs["name"] == "execution"][0]
self.loginData["lt"] = [element.attrs["value"] for element in reponse.html.find(
"input") if element.attrs["name"] == "lt"][0]
self.loginData["execution"] = [element.attrs["value"] for element in reponse.html.find(
"input") if element.attrs["name"] == "execution"][0]
reponse = session.post(self.url, data=self.loginData)
# page des résultats intermédiaire
try:
url = [element.attrs["href"] for element in reponse.html.find('a') if "id" in element.attrs if element.attrs["id"] == "service-407"][0]
url = [element.attrs["href"] for element in reponse.html.find(
'a') if "id" in element.attrs if element.attrs["id"] == "service-407"][0]
except IndexError: # Arrive quand "An Error Has Occurred"
raise TimeoutError("Le site a prit trop de temps pour répondre, veuillez réessayez plus tard.")
raise TimeoutError(
"Le site a prit trop de temps pour répondre, veuillez réessayez plus tard.")
reponse = session.get(url, allow_redirects=False)
url = reponse.headers["Location"]
reponse = session.get(url)
@ -42,7 +46,8 @@ class Universite:
# 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')}"
reponse = session.get(url)
anneesTemp = [element for element in reponse.html.find('a') if "href" in element.attrs if element.attrs["href"] == '#'][6:]
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 = []
@ -56,9 +61,11 @@ class Universite:
resultat[annee.text] = None
reponse.html.render(script=annee.attrs["onclick"][7:])
reponse = session.post(url.replace("render", "action").replace("detail", ""))
reponse = session.post(url.replace(
"render", "action").replace("detail", ""))
reponse = session.get(url.replace("action", "render").replace("notes", "detailnotes"))
reponse = session.get(url.replace(
"action", "render").replace("notes", "detailnotes"))
self.ecrirePageHTML(annee.text, reponse.text)
return resultat
@ -71,6 +78,7 @@ class Universite:
"""Affiche les notes dans stdout."""
print(self.affichageNotes(self.recuperationNotes()))
if __name__ == "__main__":
nom = argv.pop(0)
if len(argv) == 3:
@ -78,7 +86,8 @@ if __name__ == "__main__":
else:
load_dotenv()
try:
Universite(environ["URL"], environ["LOGIN"], environ["PASSWORD"]).notes()
Universite(environ["URL"], environ["LOGIN"],
environ["PASSWORD"]).notes()
except KeyError:
raise Exception(f"""
\nMerci de renseigner l'URL, le pseudo et le mot de passe (avec des \"). \

2
requirements.txt Normal file
View file

@ -0,0 +1,2 @@
requests-html==0.10.0
python-dotenv==0.19.2