Compare commits
2 commits
578657d350
...
8b6daaab3a
Author | SHA1 | Date | |
---|---|---|---|
8b6daaab3a | |||
6bc4f69cd5 |
5 changed files with 19 additions and 15 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -69,7 +69,7 @@ checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db"
|
|||
|
||||
[[package]]
|
||||
name = "cal8tor"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"clap",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "cal8tor"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
authors = ["Mylloon"]
|
||||
edition = "2021"
|
||||
description = "Extractor of the calendar of the IT degree of university Paris 8"
|
||||
|
|
15
src/info.rs
15
src/info.rs
|
@ -3,8 +3,10 @@ use regex::{Captures, Regex};
|
|||
use scraper::{Html, Selector};
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub async fn info() -> HashMap<usize, Vec<(DateTime<Utc>, i64)>> {
|
||||
let document = get_webpage().await.expect("Can't reach info website.");
|
||||
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.");
|
||||
|
||||
// Selectors
|
||||
let sel_ul = Selector::parse("ul").unwrap();
|
||||
|
@ -58,14 +60,11 @@ pub async fn info() -> HashMap<usize, Vec<(DateTime<Utc>, i64)>> {
|
|||
}
|
||||
|
||||
/// Get info webpage
|
||||
async fn get_webpage() -> Result<Html, Box<dyn std::error::Error>> {
|
||||
async fn get_webpage(user_agent: &str) -> Result<Html, Box<dyn std::error::Error>> {
|
||||
let url = "https://informatique.up8.edu/licence-iv/edt";
|
||||
|
||||
// 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()?;
|
||||
// Use custom User-Agent
|
||||
let client = reqwest::Client::builder().user_agent(user_agent).build()?;
|
||||
let html = client.get(url).send().await?.text().await?;
|
||||
|
||||
// Panic on error
|
||||
|
|
|
@ -51,16 +51,18 @@ 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).await;
|
||||
let timetable = timetable::timetable(year, args.semester, letter, &user_agent).await;
|
||||
|
||||
println!("Récupération des informations par rapport à l'année...");
|
||||
let info = info::info().await;
|
||||
let info = info::info(&user_agent).await;
|
||||
|
||||
if args.export.is_some() {
|
||||
// Export the calendar
|
||||
|
|
|
@ -15,10 +15,11 @@ 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)
|
||||
let document = get_webpage(year, semester, letter, user_agent)
|
||||
.await
|
||||
.expect("Can't reach timetable website.");
|
||||
|
||||
|
@ -126,6 +127,7 @@ 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.";
|
||||
|
@ -168,8 +170,9 @@ async fn get_webpage(
|
|||
}
|
||||
};
|
||||
|
||||
// Get raw html
|
||||
let html = reqwest::get(&url).await?.text().await?;
|
||||
// Use custom User-Agent
|
||||
let client = reqwest::Client::builder().user_agent(user_agent).build()?;
|
||||
let html = client.get(&url).send().await?.text().await?;
|
||||
|
||||
// Panic on error
|
||||
crate::utils::check_errors(&html, &url);
|
||||
|
|
Reference in a new issue