fix login

This commit is contained in:
Mylloon 2023-01-13 19:23:01 +01:00
parent 606093b1f1
commit bce24919eb
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
3 changed files with 28 additions and 14 deletions

2
.gitignore vendored
View file

@ -1,3 +1 @@
/target
*.html

View file

@ -1,22 +1,19 @@
use scraper::{Html, Selector};
use std::io::Write;
use crate::utils::write_html;
/// Retrieves marks for a user
pub async fn get_marks(username: String, password: String, user_agent: &str) {
// Login
let client = login(username, password, user_agent).await.unwrap();
// Marks
let document = load_marks(&client).await.unwrap();
let page = load_marks(&client).await.unwrap();
// DEBUG - Output to temp.html
let mut f = std::fs::OpenOptions::new()
.write(true)
.open("./temp.html")
.unwrap();
f.write_all(document.html().as_bytes()).unwrap();
f.flush().unwrap();
write_html(page.html());
}
/// Login to eP8
async fn login(
username: String,
password: String,
@ -54,7 +51,7 @@ async fn login(
let params = [
("username", username.as_str()),
("password", password.as_str()),
("_eventID", "submit"),
("_eventId", "submit"),
("submit", "SE CONNECTER"),
("lt", lt),
("execution", execution),
@ -72,14 +69,13 @@ async fn login(
Ok(client)
}
/// Load marks from scolarite-etudiant
async fn load_marks(client: &reqwest::Client) -> Result<Html, Box<dyn std::error::Error>> {
let html = client
.get("https://scolarite-etudiant.univ-paris8.fr/mondossierweb/#!notesView")
.send()
.await?;
println!("{:#?}", html);
let document = Html::parse_document(&html.text().await?);
Ok(document)

View file

@ -1,5 +1,6 @@
use std::io::{self, Write};
/// Ask user for something
pub fn ask(text: &str) -> std::string::String {
let mut user_input = String::new();
let stdin = io::stdin();
@ -10,3 +11,22 @@ pub fn ask(text: &str) -> std::string::String {
user_input.trim_end().to_string()
}
/// Write a document to a file
///
/// `html_data` may be created with something like that:
/// ```
/// Html::parse_document(
/// &client
/// .get("URL")
/// .send()
/// .await?
/// .text()
/// .await?,
/// )
/// .html(),
/// ```
pub fn write_html(html_data: String) {
let mut f = std::fs::File::create("./target/temp.html").unwrap();
write!(&mut f, "{}", html_data).unwrap();
}