From 650d1b2e6cabb22ceb41e066b1e2bc1e3434ab45 Mon Sep 17 00:00:00 2001 From: Jana Lemke Date: Wed, 24 May 2023 11:11:12 +0200 Subject: [PATCH] Initial commit --- .gitignore | 2 ++ Cargo.toml | 13 ++++++++ notes.md | 12 +++++++ src/main.rs | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 117 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 notes.md create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..869df07 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +Cargo.lock \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..524c131 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "ibis" +version = "0.1.0" +authors = ["Jana Lemke "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +structopt = "0.3.16" +serde = { version = "1.0", features = ["derive"]} +toml = "0.5.7" +glob = "0.3.0" \ No newline at end of file diff --git a/notes.md b/notes.md new file mode 100644 index 0000000..2c246c3 --- /dev/null +++ b/notes.md @@ -0,0 +1,12 @@ +# Things to do next +- Ability to list lectures +- Interface to rofi +- Ability to choose current course/lecture + +# If you are bored +- Think about better error handling +- Think about better code separation/organization + +# WISHLIST +- automatically web-archive/download/gitscrape all course websites +- download all moodle-materials \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..81dc610 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,90 @@ +use serde::{Deserialize, Serialize}; +use structopt::StructOpt; +use std::path::{Path, PathBuf}; +use glob::glob; +use std::fs::File; +use std::io::prelude::*; + +#[derive(Serialize, Deserialize)] +struct Config { + link_path: PathBuf, + files_root: PathBuf, +} + +#[derive(Serialize, Deserialize)] +struct Course{ + name: String, + short: String, + semester: String, + url: Option, + moodle: Option +} +#[derive(StructOpt)] +struct Cli { + #[structopt(subcommand)] + cmd: Option, +} + +#[derive(StructOpt)] +enum Command { + List(ObjectStruct), + Select(ObjectStruct), + Add(ObjectStruct), + Init, +} + +#[derive(StructOpt)] +struct ObjectStruct { + #[structopt(subcommand)] + object: Option, +} +#[derive(StructOpt, Debug)] +enum Object { + Courses, + Lectures, +} + +fn main() { + let conf = Config{link_path: PathBuf::from("/home/jana/current-course"), files_root: PathBuf::from("/home/jana/uni")}; + let args = Cli::from_args(); + match args.cmd { + Some(subcommand) => match subcommand { + Command::List(object) => list(object.object, conf), + Command::Add(object) => (), + Command::Select(object) => (), + Command::Init => (), + }, + None => println!("No command given"), + } +} + +fn list(object: Option, conf: Config) { + if object.is_some() { + let object = object.unwrap(); + match object { + Object::Courses => {list_courses(conf);}, + Object::Lectures => list_lectures(), + } + } +} + +fn list_courses(conf: Config) -> Vec{ + let mut courses: Vec = vec![]; + let pattern = [conf.files_root.canonicalize().unwrap().to_str().unwrap(), "/**/course.toml"].concat(); + let mut handle; + for entry in glob(pattern.as_str()).unwrap(){ + let path = entry.unwrap(); + let mut coursestring = String::new(); + handle = File::open(path).unwrap(); + handle.read_to_string(&mut coursestring); + courses.push(toml::from_str(&coursestring).unwrap()); + } + for c in &courses{ + println!("Course {}({}) in {}, url {:?}, moodle {:?}", c.name, c.short, c.semester, c.url, c.moodle); + } + courses +} + +fn list_lectures() { + println!("Listing lectures") +}