Archived
1
0
Fork 0
forked from Anri/cal8tor

use tuple instead of hashmaps

This commit is contained in:
Mylloon 2022-08-16 09:33:35 +02:00
parent 6ecf7551a2
commit 37a4e61ce5
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 10 additions and 5 deletions

View file

@ -3,7 +3,12 @@ use ics::{
Event, ICalendar, Event, ICalendar,
}; };
type T = Vec<crate::timetable::models::Day>; type T = (
// Schedules
Vec<String>,
// Timetable per days with the semester as the key
(usize, Vec<crate::timetable::models::Day>),
);
type D = std::collections::HashMap< type D = std::collections::HashMap<
usize, usize,
Vec<(chrono::DateTime<chrono::Utc>, chrono::DateTime<chrono::Utc>)>, Vec<(chrono::DateTime<chrono::Utc>, chrono::DateTime<chrono::Utc>)>,
@ -36,5 +41,7 @@ pub fn export(_timetable: T, _dates: D) -> ICalendar<'static> {
calendar.save_file("target/debug2.ics").unwrap(); calendar.save_file("target/debug2.ics").unwrap();
println!("{:#?} - {:#?}", _timetable, _dates);
calendar calendar
} }

View file

@ -1,5 +1,3 @@
use std::collections::HashMap;
use scraper::{Html, Selector}; use scraper::{Html, Selector};
pub mod models; pub mod models;
@ -9,7 +7,7 @@ pub async fn timetable(
year: i8, year: i8,
semester: i8, semester: i8,
letter: Option<char>, letter: Option<char>,
) -> HashMap<usize, Vec<models::Day>> { ) -> (Vec<String>, (usize, Vec<models::Day>)) {
let document = get_webpage(year, semester, letter) let document = get_webpage(year, semester, letter)
.await .await
.expect("Can't reach timetable website."); .expect("Can't reach timetable website.");
@ -100,7 +98,7 @@ pub async fn timetable(
panic!("Error when building the timetable."); panic!("Error when building the timetable.");
} }
HashMap::from([(semester as usize, timetable)]) (schedules, (semester as usize, timetable))
} }
/// Get timetable webpage /// Get timetable webpage