// SPDX-License-Identifier: AGPL-3.0-or-later //! # VUW Course scraper //! //! This is a simple program capable of parsing VUWs courses from the registry. It cannot correctly //! parse prerequisites, however. use std::{collections::HashMap, fs}; use scraper::Html; use serde::{Deserialize, Serialize}; use tracing::level_filters::LevelFilter; use vuw_course_scraper::{parse_document, Course}; /// Utility struct for exporting to JSON. #[derive(Clone, Deserialize, Serialize)] struct JsonExport<'a> { /// [`HashMap`] of all courses. #[serde(borrow)] courses: HashMap<&'a str, Course<'a>>, } fn main() { tracing_subscriber::fmt() .with_max_level(LevelFilter::INFO) .init(); let html = &fs::read_to_string("./courses.html").expect("file does not exist"); let document = Html::parse_document(html); let course_map = parse_document(&document); fs::write( "./export.json", simd_json::serde::to_string(&JsonExport { courses: course_map, }) .expect("json should parse correctly"), ) .expect("file should be writable"); }