diff options
| author | Sophie Forrest <git@sophieforrest.com> | 2024-12-04 20:48:31 +1300 |
|---|---|---|
| committer | Sophie Forrest <git@sophieforrest.com> | 2024-12-04 20:48:31 +1300 |
| commit | 3bd5ebb7b8f938ba57a114cd77c0b5c5ad3bf93e (patch) | |
| tree | 8bbd29ab03e19e584644b7b51356fd09dcac5e13 /src | |
| parent | 3725fe07e58f459bb7ab9fcbc10775cf4b138ec8 (diff) | |
Allows choosing the year and file path.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib.rs | 3 | ||||
| -rw-r--r-- | src/main.rs | 47 |
2 files changed, 34 insertions, 16 deletions
diff --git a/src/lib.rs b/src/lib.rs index ee08cbc..2899da1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,8 +2,7 @@ //! # VUW Course scraper //! -//! This is a simple program capable of parsing VUWs courses from the registry. It cannot correctly -//! parse prerequisites, however. +//! Program capable of parsing VUWs courses from the registry. mod parser; diff --git a/src/main.rs b/src/main.rs index b13c8cf..f5dd05f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,11 +2,14 @@ //! # VUW Course scraper //! -//! This is a simple program capable of parsing VUWs courses from the registry. It cannot correctly -//! parse prerequisites, however. +//! Program capable of parsing VUWs courses from the registry. -use std::collections::{BTreeMap, HashMap}; +use std::{ + collections::{BTreeMap, HashMap}, + path::PathBuf, +}; +use clap::Parser; use futures_util::future::join_all; use scraper::Html; use serde::{Deserialize, Serialize}; @@ -22,6 +25,18 @@ struct JsonExport<'a> { courses: BTreeMap<&'a str, Course<'a>>, } +/// Arguments for command line interface. +#[derive(Clone, Parser)] +#[command(about, author, long_about = None, version)] +struct Args { + /// Year of the files to download from the website. + #[arg(short, long, default_value_t = time::OffsetDateTime::now_utc().year() + 1)] + pub year: i32, + + /// File path of the output file. + pub path: PathBuf, +} + /// Transforms a URI into a documents text form through a get request. /// /// # Panics @@ -44,16 +59,20 @@ async fn main() { .with_max_level(LevelFilter::ERROR) .init(); - let documents: Vec<Html> = - join_all( - ["d", "u", "p", "o"] - .iter() - .map(|directory| { - format!("https://service-web.wgtn.ac.nz/dotnet2/catprint.aspx?d=all&t={directory}2025") - }) - .map(into_document), - ) - .await; + let args = Args::parse(); + + let documents: Vec<Html> = join_all( + ["d", "u", "p", "o"] + .iter() + .map(|directory| { + format!( + "https://service-web.wgtn.ac.nz/dotnet2/catprint.aspx?d=all&t={directory}{}", + args.year + ) + }) + .map(into_document), + ) + .await; let all_courses: HashMap<&str, Course> = task::block_in_place(|| { documents @@ -72,7 +91,7 @@ async fn main() { let sorted_courses: BTreeMap<&str, Course> = all_courses.into_iter().collect(); fs::write( - "./export-dl.json", + args.path, task::block_in_place(|| { simd_json::serde::to_string(&JsonExport { courses: sorted_courses, |