fix login
This commit is contained in:
parent
606093b1f1
commit
bce24919eb
3 changed files with 28 additions and 14 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,3 +1 @@
|
||||||
/target
|
/target
|
||||||
|
|
||||||
*.html
|
|
||||||
|
|
20
src/marks.rs
20
src/marks.rs
|
@ -1,22 +1,19 @@
|
||||||
use scraper::{Html, Selector};
|
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) {
|
pub async fn get_marks(username: String, password: String, user_agent: &str) {
|
||||||
// Login
|
// Login
|
||||||
let client = login(username, password, user_agent).await.unwrap();
|
let client = login(username, password, user_agent).await.unwrap();
|
||||||
|
|
||||||
// Marks
|
// Marks
|
||||||
let document = load_marks(&client).await.unwrap();
|
let page = load_marks(&client).await.unwrap();
|
||||||
|
|
||||||
// DEBUG - Output to temp.html
|
write_html(page.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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Login to eP8
|
||||||
async fn login(
|
async fn login(
|
||||||
username: String,
|
username: String,
|
||||||
password: String,
|
password: String,
|
||||||
|
@ -54,7 +51,7 @@ async fn login(
|
||||||
let params = [
|
let params = [
|
||||||
("username", username.as_str()),
|
("username", username.as_str()),
|
||||||
("password", password.as_str()),
|
("password", password.as_str()),
|
||||||
("_eventID", "submit"),
|
("_eventId", "submit"),
|
||||||
("submit", "SE CONNECTER"),
|
("submit", "SE CONNECTER"),
|
||||||
("lt", lt),
|
("lt", lt),
|
||||||
("execution", execution),
|
("execution", execution),
|
||||||
|
@ -72,14 +69,13 @@ async fn login(
|
||||||
Ok(client)
|
Ok(client)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Load marks from scolarite-etudiant
|
||||||
async fn load_marks(client: &reqwest::Client) -> Result<Html, Box<dyn std::error::Error>> {
|
async fn load_marks(client: &reqwest::Client) -> Result<Html, Box<dyn std::error::Error>> {
|
||||||
let html = client
|
let html = client
|
||||||
.get("https://scolarite-etudiant.univ-paris8.fr/mondossierweb/#!notesView")
|
.get("https://scolarite-etudiant.univ-paris8.fr/mondossierweb/#!notesView")
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
println!("{:#?}", html);
|
|
||||||
|
|
||||||
let document = Html::parse_document(&html.text().await?);
|
let document = Html::parse_document(&html.text().await?);
|
||||||
|
|
||||||
Ok(document)
|
Ok(document)
|
||||||
|
|
20
src/utils.rs
20
src/utils.rs
|
@ -1,5 +1,6 @@
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
|
|
||||||
|
/// Ask user for something
|
||||||
pub fn ask(text: &str) -> std::string::String {
|
pub fn ask(text: &str) -> std::string::String {
|
||||||
let mut user_input = String::new();
|
let mut user_input = String::new();
|
||||||
let stdin = io::stdin();
|
let stdin = io::stdin();
|
||||||
|
@ -10,3 +11,22 @@ pub fn ask(text: &str) -> std::string::String {
|
||||||
|
|
||||||
user_input.trim_end().to_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();
|
||||||
|
}
|
||||||
|
|
Reference in a new issue