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