Add wod sources, and updated vimrc

This commit is contained in:
2018-02-02 09:29:13 -05:00
parent 8a46fb4c74
commit c714d87903
4 changed files with 1294 additions and 2 deletions

1241
wod/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

9
wod/Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "wod"
version = "0.1.0"
authors = ["Orien Vandenbergh <orien.vandenbergh@defpoint.com>"]
[dependencies]
reqwest = "0.8.2"
scraper = "0.4.0"
select = "0.4.2"

41
wod/src/main.rs Normal file
View File

@ -0,0 +1,41 @@
extern crate reqwest;
extern crate scraper;
extern crate select;
use select::document::Document;
use select::predicate::{Class,Name,Predicate};
fn main() {
if is_cached() {
} else {
wod("http://www.merriam-webster.com/word-of-the-day");
}
}
fn is_cached() -> bool {
return false;
}
fn wod(url: &str) {
let yellow = "\x1b[1;33m";
let purple = "\x1b[0;35m";
let nc = "\x1b[0m";
let resp = reqwest::get(url).unwrap();
assert!(resp.status().is_success());
let document = Document::from_read(resp).unwrap();
let node = document.find(Class("word-header")).next().unwrap();
let word = node.find(Name("h1")).next().unwrap().text();
let node = document.find(Class("word-attributes")).next().unwrap();
let attr = node.find(Class("main-attr")).next().unwrap().text();
let syllables = node.find(Class("word-syllables")).next().unwrap().text();
println!("Word of the Day: {}{} : {} ({}){}", yellow, word, attr, syllables, nc);
for definition in document.find(Class("wod-definition-container").child(Name("p"))) {
let children: Vec<String> = definition.children().map(|n| n.text()).collect();
let texts = children.join("");
println!(" definition: {}{}{}", purple, texts, nc);
}
}