From 9518e130263dd547eaee66b6cae846809ba2d160 Mon Sep 17 00:00:00 2001 From: Sophie Forrest Date: Sat, 5 Oct 2024 20:48:47 +1300 Subject: feat: use BTreeMap for alphabetical sorting --- src/main.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 68e378a..d02e53b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ //! This is a simple program capable of parsing VUWs courses from the registry. It cannot correctly //! parse prerequisites, however. -use std::collections::HashMap; +use std::collections::{BTreeMap, HashMap}; use futures_util::future::join_all; use scraper::Html; @@ -19,7 +19,7 @@ use vuw_course_scraper::{parse_document, Course}; struct JsonExport<'a> { /// [`HashMap`] of all courses. #[serde(borrow)] - courses: HashMap<&'a str, Course<'a>>, + courses: BTreeMap<&'a str, Course<'a>>, } /// Transforms a URI into a documents text form through a get request. @@ -49,7 +49,7 @@ async fn main() { ["d", "u", "p", "o"] .iter() .map(|directory| { - format!("https://service-web.wgtn.ac.nz/dotnet2/catprint.aspx?d=all&t={directory}2025") + format!("https://service-web.wgtn.ac.nz/dotnet2/catprint.aspx?d=all&t={directory}2024") }) .map(into_document), ) @@ -69,11 +69,13 @@ async fn main() { .expect("maps should reduce into one correctly") }); + let sorted_courses: BTreeMap<&str, Course> = all_courses.into_iter().collect(); + fs::write( "./export-dl.json", task::block_in_place(|| { simd_json::serde::to_string(&JsonExport { - courses: all_courses, + courses: sorted_courses, }) .expect("json should parse correctly") }), -- cgit 1.4.1