Compare commits

..

No commits in common. "8b6daaab3a9d73f2dd9f06fba908af7dd62b1bee" and "578657d3507d714099d235df257032815e8379ee" have entirely different histories.

5 changed files with 15 additions and 19 deletions

2
Cargo.lock generated
View file

@ -69,7 +69,7 @@ checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db"
[[package]]
name = "cal8tor"
version = "0.1.1"
version = "0.1.0"
dependencies = [
"chrono",
"clap",

View file

@ -1,6 +1,6 @@
[package]
name = "cal8tor"
version = "0.1.1"
version = "0.1.0"
authors = ["Mylloon"]
edition = "2021"
description = "Extractor of the calendar of the IT degree of university Paris 8"

View file

@ -3,10 +3,8 @@ use regex::{Captures, Regex};
use scraper::{Html, Selector};
use std::collections::HashMap;
pub async fn info(user_agent: &str) -> HashMap<usize, Vec<(DateTime<Utc>, i64)>> {
let document = get_webpage(user_agent)
.await
.expect("Can't reach info website.");
pub async fn info() -> HashMap<usize, Vec<(DateTime<Utc>, i64)>> {
let document = get_webpage().await.expect("Can't reach info website.");
// Selectors
let sel_ul = Selector::parse("ul").unwrap();
@ -60,11 +58,14 @@ pub async fn info(user_agent: &str) -> HashMap<usize, Vec<(DateTime<Utc>, i64)>>
}
/// Get info webpage
async fn get_webpage(user_agent: &str) -> Result<Html, Box<dyn std::error::Error>> {
async fn get_webpage() -> Result<Html, Box<dyn std::error::Error>> {
let url = "https://informatique.up8.edu/licence-iv/edt";
// Use custom User-Agent
let client = reqwest::Client::builder().user_agent(user_agent).build()?;
// We don't use reqwest::get() but a client with a custom user-agent
// in order to avoid getting rate limit
let client = reqwest::Client::builder()
.user_agent("bypass-rate_limit")
.build()?;
let html = client.get(url).send().await?.text().await?;
// Panic on error

View file

@ -51,18 +51,16 @@ async fn main() {
None => "",
};
let user_agent = format!("cal8tor/{}", env!("CARGO_PKG_VERSION"));
println!(
"Récupération de l'emploi du temps des L{}{}{}...",
year,
seperator,
letter.unwrap_or_default().to_uppercase()
);
let timetable = timetable::timetable(year, args.semester, letter, &user_agent).await;
let timetable = timetable::timetable(year, args.semester, letter).await;
println!("Récupération des informations par rapport à l'année...");
let info = info::info(&user_agent).await;
let info = info::info().await;
if args.export.is_some() {
// Export the calendar

View file

@ -15,11 +15,10 @@ pub async fn timetable(
year: i8,
semester_opt: Option<i8>,
letter: Option<char>,
user_agent: &str,
) -> (Vec<String>, (usize, Vec<models::Day>)) {
let semester = get_semester(semester_opt, letter);
let document = get_webpage(year, semester, letter, user_agent)
let document = get_webpage(year, semester, letter)
.await
.expect("Can't reach timetable website.");
@ -127,7 +126,6 @@ async fn get_webpage(
year: i8,
semester: i8,
letter: Option<char>,
user_agent: &str,
) -> Result<Html, Box<dyn std::error::Error>> {
let url = {
let panic_semester_message = "Unknown semester.";
@ -170,9 +168,8 @@ async fn get_webpage(
}
};
// Use custom User-Agent
let client = reqwest::Client::builder().user_agent(user_agent).build()?;
let html = client.get(&url).send().await?.text().await?;
// Get raw html
let html = reqwest::get(&url).await?.text().await?;
// Panic on error
crate::utils::check_errors(&html, &url);