diff --git a/codegen/.gitignore b/codegen/.gitignore new file mode 100644 index 00000000..eb5a316c --- /dev/null +++ b/codegen/.gitignore @@ -0,0 +1 @@ +target diff --git a/codegen/Cargo.toml b/codegen/Cargo.toml new file mode 100644 index 00000000..2c4c2efd --- /dev/null +++ b/codegen/Cargo.toml @@ -0,0 +1,9 @@ +[package] +authors = ["Philipp Oppermann "] +name = "codegen" +version = "0.1.0" + +[dependencies] +chrono = "0.2.25" +getopts = "0.2.14" +requests = "0.0.22" diff --git a/codegen/src/main.rs b/codegen/src/main.rs new file mode 100644 index 00000000..00ccab3e --- /dev/null +++ b/codegen/src/main.rs @@ -0,0 +1,92 @@ +extern crate requests; +extern crate getopts; +extern crate chrono; + +use chrono::Duration; +use std::fmt; + +fn main() { + use std::env; + use std::fs::File; + use std::io::Write; + + let args: Vec = env::args().collect(); + let mut opts = getopts::Options::new(); + + opts.optopt("o", "", "set output file name", "NAME"); + let matches = opts.parse(&args[1..]).unwrap(); + let output = matches.opt_str("o"); + + let pr_list = pr_list(); + + match output { + None => println!("{:?}", pr_list), + Some(output) => { + let mut file = File::create(output).expect("error while opening/creating output file"); + file.write_all(pr_list.as_bytes()).expect("error while writing to output file"); + } + } +} + +fn pr_list() -> String { + use chrono::{UTC, DateTime}; + + const URL: &'static str = "https://api.github.com/search/issues?q=repo:phil-opp/blog_os+type:\ + pr+is:merged+label:relnotes"; + + let mut ret = String::from(""); + ret +} + +struct DateFmt(Duration); + +impl fmt::Display for DateFmt { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + try!(write!(f, r#"