Initial commit
This commit is contained in:
commit
3e48c36870
4 changed files with 117 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
/target
|
||||||
|
Cargo.lock
|
||||||
13
Cargo.toml
Normal file
13
Cargo.toml
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
[package]
|
||||||
|
name = "ibis"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Jana Lemke <jana.lemke@rwth-aachen.de>"]
|
||||||
|
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"
|
||||||
12
notes.md
Normal file
12
notes.md
Normal file
|
|
@ -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
|
||||||
90
src/main.rs
Normal file
90
src/main.rs
Normal file
|
|
@ -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<String>,
|
||||||
|
moodle: Option<String>
|
||||||
|
}
|
||||||
|
#[derive(StructOpt)]
|
||||||
|
struct Cli {
|
||||||
|
#[structopt(subcommand)]
|
||||||
|
cmd: Option<Command>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(StructOpt)]
|
||||||
|
enum Command {
|
||||||
|
List(ObjectStruct),
|
||||||
|
Select(ObjectStruct),
|
||||||
|
Add(ObjectStruct),
|
||||||
|
Init,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(StructOpt)]
|
||||||
|
struct ObjectStruct {
|
||||||
|
#[structopt(subcommand)]
|
||||||
|
object: Option<Object>,
|
||||||
|
}
|
||||||
|
#[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<Object>, 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<Course>{
|
||||||
|
let mut courses: Vec<Course> = 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")
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue