summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSophie Forrest <git@sophieforrest.com>2024-10-05 20:48:47 +1300
committerSophie Forrest <git@sophieforrest.com>2024-10-05 20:48:47 +1300
commit9518e130263dd547eaee66b6cae846809ba2d160 (patch)
tree5b24e009e4e03e8cd399affc3920055b5dd30d09
parente0587ef07fdef9371e70ef54479cc9c597f53615 (diff)
feat: use BTreeMap for alphabetical sorting
-rw-r--r--src/main.rs10
1 files changed, 6 insertions, 4 deletions
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")
}),