Compare commits

..

No commits in common. "main" and "0.4.3" have entirely different histories.
main ... 0.4.3

4 changed files with 649 additions and 499 deletions

1094
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,21 +1,21 @@
[package] [package]
name = "cal8tor" name = "cal8tor"
version = "0.4.5" version = "0.4.3"
authors = ["Mylloon"] authors = ["Mylloon"]
edition = "2021" edition = "2021"
description = "Extractor of the calendar of the IT degree of university Paris 8" description = "Extractor of the calendar of the IT degree of university Paris 8"
readme = "README.md" readme = "README.md"
repository = "https://git.mylloon.fr/Anri/cal8tor" repository = "https://git.kennel.ml/Anri/cal8tor"
keywords = ["scrape", "calendar"] keywords = ["scrape", "calendar"]
publish = false publish = false
license = "AGPL-3.0-or-later" license = "AGPL-3.0-or-later"
[dependencies] [dependencies]
reqwest = { version = "0.11" } reqwest = { version = "0.11" }
tokio = { version = "1.32", features = ["full"] } tokio = { version = "1.27", features = ["full"] }
scraper = "0.17" scraper = "0.16"
regex = "1.9" regex = "1.7.3"
chrono = "0.4.28" chrono = "0.4.24"
ics = "0.5" ics = "0.5"
uuid = { version = "1.4", features = ["v4", "fast-rng"] } uuid = { version = "1.2.2", features = ["v4", "fast-rng"] }
clap = { version = "4.4", features = ["derive"] } clap = { version = "4.0.32", features = ["derive"] }

View file

@ -1,4 +1,4 @@
use chrono::{DateTime, Utc}; use chrono::{DateTime, TimeZone, Utc};
use regex::{Captures, Regex}; use regex::{Captures, Regex};
use scraper::{Html, Selector}; use scraper::{Html, Selector};
use std::collections::HashMap; use std::collections::HashMap;
@ -77,17 +77,9 @@ async fn get_webpage(user_agent: &str) -> Result<Html, Box<dyn std::error::Error
fn anglophonization(date: &str) -> String { fn anglophonization(date: &str) -> String {
let dico = HashMap::from([ let dico = HashMap::from([
("janvier", "january"), ("janvier", "january"),
("février", "february"),
("mars", "march"), ("mars", "march"),
("avril", "april"),
("mai", "may"),
("juin", "june"),
("juillet", "july"),
("août", "august"),
("septembre", "september"), ("septembre", "september"),
("octobre", "october"),
("novembre", "november"), ("novembre", "november"),
("décembre", "december"),
]); ]);
// New regex of all the french month // New regex of all the french month
@ -98,13 +90,13 @@ fn anglophonization(date: &str) -> String {
.unwrap(); .unwrap();
format!( format!(
// Use 12:00 and UTC TZ for chrono parser // Use 12:00 for chrono parser
"{} 12:00 +0000", "{} 12:00",
// Replace french by english month // Replace french by english month
re.replace_all(date, |cap: &Captures| match &cap[0] { re.replace_all(date, |cap: &Captures| {
match &cap[0] {
month if dico.contains_key(month) => dico.get(month).unwrap(), month if dico.contains_key(month) => dico.get(month).unwrap(),
month => { month => panic!("Unknown month: {}", month),
panic!("Unknown month: {}", month)
} }
}) })
) )
@ -114,7 +106,6 @@ fn anglophonization(date: &str) -> String {
fn get_date(date: &str) -> DateTime<Utc> { fn get_date(date: &str) -> DateTime<Utc> {
// Use and keep UTC time, we have the hour set to 12h and // Use and keep UTC time, we have the hour set to 12h and
// Paris 8 is in France so there is no problems // Paris 8 is in France so there is no problems
DateTime::parse_from_str(&anglophonization(date), "%e %B %Y %H:%M %z") Utc.datetime_from_str(&anglophonization(date), "%e %B %Y %H:%M")
.unwrap() .unwrap()
.into()
} }

View file

@ -85,11 +85,14 @@ pub async fn timetable(
} }
None => None, None => None,
}, },
room: capitalize(&mut match course.select(&sel_strong).next() { room: capitalize(
Some(el) => el.inner_html().replace("<br>", ""), &mut course
// Error in the site, silently passing... (the room is probably at the professor member) .select(&sel_strong)
None => String::new(), .next()
}), .unwrap()
.inner_html()
.replace("<br>", ""),
),
start: location_tracker, start: location_tracker,
size: match course.value().attr("colspan") { size: match course.value().attr("colspan") {
Some(i) => i.parse().unwrap(), Some(i) => i.parse().unwrap(),