aboutsummaryrefslogtreecommitdiff
path: root/src/pre_process.rs
blob: d69cfce8109ec91ac0c19589274f6db84d88aae9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use super::regex::Regex;

pub fn strip_irrelevant_content(s: &str) -> String {
    let mut retn = "";
    match s.find(r#"<div class=profile id=profile>"#) {
        Some(pos) => retn = &s[pos..],
        None => (),
    };

    match s.find(r#"<INPUT style="font-size: 2em;" TYPE=SUBMIT NAME="votes" VALUE="Cast Votes">"#) {
        Some(pos) => retn = &s[..pos],
        None => (),
    };
    return retn.into();
}

pub struct Section {
    pub name: String,
    pub re: Regex,
    pub content: String,
}

pub fn split_sections(d: &str, s: &mut Vec<Section>) {
    for section in s {
        for m in section.re.captures_iter(d) {
            assert!(m.len() > 1);
            section.content = format!("{}", m.at(1).unwrap());
        }
    }
}