Compare commits

..

8 commits
0.4.3 ... main

Author SHA1 Message Date
a56103d4c7
update repo link 2023-09-18 18:47:23 +02:00
79cc041251
0.4.5 release 2023-09-07 18:52:09 +02:00
c9262519c3
Remove debug entry 2023-09-07 18:51:41 +02:00
f1a8bbe571
0.4.4 release 2023-09-07 18:30:08 +02:00
32329647bc
Update deps 2023-09-07 18:29:09 +02:00
e4aa5864eb
Add missing months 2023-09-07 18:20:51 +02:00
e1fc4b7a51
Resolve E0308 ?? 2023-09-07 18:19:29 +02:00
e18b11a5fe
Don't crash when the class isn't bold 2023-04-23 01:35:00 +02:00
4 changed files with 499 additions and 649 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.3" version = "0.4.5"
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.kennel.ml/Anri/cal8tor" repository = "https://git.mylloon.fr/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.27", features = ["full"] } tokio = { version = "1.32", features = ["full"] }
scraper = "0.16" scraper = "0.17"
regex = "1.7.3" regex = "1.9"
chrono = "0.4.24" chrono = "0.4.28"
ics = "0.5" ics = "0.5"
uuid = { version = "1.2.2", features = ["v4", "fast-rng"] } uuid = { version = "1.4", features = ["v4", "fast-rng"] }
clap = { version = "4.0.32", features = ["derive"] } clap = { version = "4.4", features = ["derive"] }

View file

@ -1,4 +1,4 @@
use chrono::{DateTime, TimeZone, Utc}; use chrono::{DateTime, 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,9 +77,17 @@ 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
@ -90,13 +98,13 @@ fn anglophonization(date: &str) -> String {
.unwrap(); .unwrap();
format!( format!(
// Use 12:00 for chrono parser // Use 12:00 and UTC TZ for chrono parser
"{} 12:00", "{} 12:00 +0000",
// Replace french by english month // Replace french by english month
re.replace_all(date, |cap: &Captures| { re.replace_all(date, |cap: &Captures| match &cap[0] {
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)
} }
}) })
) )
@ -106,6 +114,7 @@ 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
Utc.datetime_from_str(&anglophonization(date), "%e %B %Y %H:%M") DateTime::parse_from_str(&anglophonization(date), "%e %B %Y %H:%M %z")
.unwrap() .unwrap()
.into()
} }

View file

@ -85,14 +85,11 @@ pub async fn timetable(
} }
None => None, None => None,
}, },
room: capitalize( room: capitalize(&mut match course.select(&sel_strong).next() {
&mut course Some(el) => el.inner_html().replace("<br>", ""),
.select(&sel_strong) // Error in the site, silently passing... (the room is probably at the professor member)
.next() None => String::new(),
.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(),