@@ 30,26 30,32 @@ fn main() -> std::result::Result<(), Box<dyn Error>> {
let name_pattern = Regex::new(r"(?:^\s+\d+\W+)([A-zÁ-ÿ\s]{2,})(?:\s\s|\()").unwrap();
let dob_pattern = Regex::new(r"\((?:(?:born\s)?(\d+))?(?:–\d+)?\)").unwrap();
let dod_pattern = Regex::new(r"\(\d+–(\d+)\)").unwrap();
- let tenure_pattern = Regex::new(r"(\w+\s\d+,\s+\d+)\s*((?:\w+\s\d+,\s+\d+)|Incumbent)?").unwrap();
+ let tenure_pattern =
+ Regex::new(r"(\w+\s\d+,\s+\d+)\s*((?:\w+\s\d+,\s+\d+)|Incumbent)?").unwrap();
let node = table_match.as_node();
for row_match in node.select("tr:not(:first-child)").unwrap() {
- let text = row_match.text_contents()
- .replace("\n", " ");
+ let text = row_match.text_contents().replace("\n", " ");
+
+ let img = row_match.as_node().select_first("img");
- let img = row_match.as_node()
- .select_first("img");
-
let img = if let Ok(i) = img {
- i.attributes.borrow().get("src").unwrap_or_default().to_string()
+ i.attributes
+ .borrow()
+ .get("src")
+ .unwrap_or_default()
+ .to_string()
} else {
"".to_string()
};
-
- let img = img.replace("thumb/", "")
- .rsplitn(2,'/').last().unwrap_or_default().to_string();
-
+ let img = img
+ .replace("thumb/", "")
+ .rsplitn(2, '/')
+ .last()
+ .unwrap_or_default()
+ .to_string();
+
let caps = name_pattern.captures(&text);
if caps.is_none() {
continue;
@@ 75,16 81,16 @@ fn main() -> std::result::Result<(), Box<dyn Error>> {
None
};
- let person = Person{
- name: name.to_string(),
+ let person = Person {
+ name: name.to_string(),
dob: dob.parse::<i32>().unwrap(),
dod,
start: start.to_string(),
end,
- img: format!("https:{}", img)
+ img: format!("https:{}", img),
};
- println!("{:?}", person);
+ println!("{:?}", person);
}
}