Add wod sources, and updated vimrc

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

5
vimrc
View File

@ -14,6 +14,7 @@
" * https://github.com/scrooloose/syntastic
" * https://github.com/hashivim/vim-terraform.git
" * https://github.com/tangledhelix/vim-kickstart.git
" * git@github.com:yorokobi/vim-splunk.git
"
" Pathogen colorschemes used: (vimcolors.com for more)
" * https://github.com/Marfisc/vorange.git
@ -46,8 +47,8 @@ set comments-=s1:/*,mb:*,ex:*/
set comments+=s:/*,mb:\ *,ex:\ */
set comments+=fb:*
" Highlight the focused line
set cursorline
" If uncommented highlight the focused line
"set cursorline
"set background=dark
"let g:badwolf_darkgutter=1

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);
}
}