Compare commits
4 Commits
08bf7ed29e
...
0f0b044993
Author | SHA1 | Date |
---|---|---|
Bauke | 0f0b044993 | |
Bauke | 2b944b57af | |
Bauke | cd560973ed | |
Bauke | f8969623c6 |
|
@ -1,6 +1,11 @@
|
|||
//! Parsing for `/~<group>`.
|
||||
|
||||
use {color_eyre::Result, scraper::Html};
|
||||
use std::str::FromStr;
|
||||
|
||||
use {
|
||||
color_eyre::{eyre::Error, Result},
|
||||
scraper::Html,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
regexes::GROUP_SUBSCRIBERS_RE,
|
||||
|
@ -42,6 +47,15 @@ pub struct GroupWikiLink {
|
|||
pub url: String,
|
||||
}
|
||||
|
||||
impl FromStr for Group {
|
||||
type Err = Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let html = Html::parse_document(s);
|
||||
Self::from_html(&html)
|
||||
}
|
||||
}
|
||||
|
||||
impl Group {
|
||||
/// Parses a [`Group`] from a [`scraper::Html`] tree.
|
||||
pub fn from_html(html: &Html) -> Result<Self> {
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
//! Parsing for [`/groups`](https://tildes.net/groups).
|
||||
|
||||
use {color_eyre::Result, scraper::Html};
|
||||
use std::str::FromStr;
|
||||
|
||||
use {
|
||||
color_eyre::{eyre::Error, Result},
|
||||
scraper::Html,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
regexes::{DUPLICATE_WHITESPACE_RE, GROUP_LIST_ACTIVITY_RE},
|
||||
|
@ -32,6 +37,15 @@ pub struct GroupListSummary {
|
|||
pub topic_activity: Option<i32>,
|
||||
}
|
||||
|
||||
impl FromStr for GroupList {
|
||||
type Err = Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let html = Html::parse_document(s);
|
||||
Self::from_html(&html)
|
||||
}
|
||||
}
|
||||
|
||||
impl GroupList {
|
||||
/// Parses a [`GroupList`] from a [`scraper::Html`] tree.
|
||||
pub fn from_html(html: &Html) -> Result<Self> {
|
||||
|
|
|
@ -30,5 +30,4 @@ pub(crate) mod group_list;
|
|||
pub use {
|
||||
group::{Group, GroupWikiLink},
|
||||
group_list::{GroupList, GroupListSummary},
|
||||
scraper::Html,
|
||||
};
|
||||
|
|
|
@ -23,7 +23,7 @@ lazy_static! {
|
|||
/// Selector for the group subscriber count.
|
||||
pub static ref GROUP_SUBSCRIBERS: Selector = selector(".group-subscription-count");
|
||||
|
||||
/// Selector for group wiki links.
|
||||
/// Selector for sub groups.
|
||||
pub static ref GROUP_SUB_GROUP_LINKS: Selector = selector(r#"#sidebar .link-group"#);
|
||||
|
||||
/// Selector for group wiki links.
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
use std::fs::read_to_string;
|
||||
|
||||
use {insta::assert_debug_snapshot, scraper::Html, tildes_parser::Group};
|
||||
use {insta::assert_debug_snapshot, tildes_parser::Group};
|
||||
|
||||
#[test]
|
||||
fn test_group_parsing() {
|
||||
let html = read_to_string("tests/samples/group.html").unwrap();
|
||||
let html = Html::parse_document(&html);
|
||||
let group = Group::from_html(&html).unwrap();
|
||||
let group = &html.parse::<Group>().unwrap();
|
||||
assert_debug_snapshot!(group);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
use std::fs::read_to_string;
|
||||
|
||||
use {insta::assert_debug_snapshot, scraper::Html, tildes_parser::GroupList};
|
||||
use {insta::assert_debug_snapshot, tildes_parser::GroupList};
|
||||
|
||||
#[test]
|
||||
fn test_group_list_parsing() {
|
||||
let html = read_to_string("tests/samples/group_list.html").unwrap();
|
||||
let html = Html::parse_document(&html);
|
||||
let group_list = GroupList::from_html(&html).unwrap();
|
||||
let group_list = html.parse::<GroupList>().unwrap();
|
||||
assert_debug_snapshot!(group_list);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue