extract prelude and feed::find
This commit is contained in:
parent
ec20864dac
commit
507447f6ad
5 changed files with 33 additions and 29 deletions
20
src/feed/find.rs
Normal file
20
src/feed/find.rs
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
pub fn get_feed_url(site: &str, channel_name: &str) -> Result<String> {
|
||||||
|
if let Some(channel_prefix) = channel_name.chars().next() {
|
||||||
|
if channel_prefix != '@' {
|
||||||
|
return Err(format!("Channel Name must begin with an '@': {}", channel_name).into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let channel_url = format!("{}{}", site, channel_name);
|
||||||
|
let response = reqwest::blocking::get(channel_url)?;
|
||||||
|
let rss_url = scraper::Html::parse_document(&response.text()?)
|
||||||
|
.select(&scraper::Selector::parse("link[title='RSS']").unwrap())
|
||||||
|
.next()
|
||||||
|
.unwrap()
|
||||||
|
.value()
|
||||||
|
.attr("href")
|
||||||
|
.unwrap()
|
||||||
|
.to_string();
|
||||||
|
Ok(rss_url)
|
||||||
|
}
|
3
src/feed/mod.rs
Normal file
3
src/feed/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
mod find;
|
||||||
|
|
||||||
|
pub use find::get_feed_url;
|
32
src/lib.rs
32
src/lib.rs
|
@ -5,21 +5,16 @@ use std::fs::File;
|
||||||
use atom_syndication::{Entry, Feed, Link};
|
use atom_syndication::{Entry, Feed, Link};
|
||||||
|
|
||||||
mod errors;
|
mod errors;
|
||||||
use errors::Error;
|
mod feed;
|
||||||
|
pub mod prelude;
|
||||||
|
|
||||||
//
|
use prelude::*;
|
||||||
// RESULTS
|
|
||||||
//
|
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
|
||||||
|
|
||||||
//
|
|
||||||
// MAIN
|
|
||||||
//
|
|
||||||
pub fn run(subscriptions: &str, history: &str, site: &str) -> Result<()> {
|
pub fn run(subscriptions: &str, history: &str, site: &str) -> Result<()> {
|
||||||
for channel_name in lines_from(subscriptions)? {
|
for channel_name in lines_from(subscriptions)? {
|
||||||
let channel_name = channel_name?;
|
let channel_name = channel_name?;
|
||||||
println!("Channel: {}", channel_name);
|
println!("Channel: {}", channel_name);
|
||||||
let feed_url = get_feed_url(site, &channel_name)?;
|
let feed_url = feed::get_feed_url(site, &channel_name)?;
|
||||||
for entry in get_feed(feed_url)?.entries() {
|
for entry in get_feed(feed_url)?.entries() {
|
||||||
if let Some(link) = get_link(entry) {
|
if let Some(link) = get_link(entry) {
|
||||||
if !is_already_downloaded(&link, history)? {
|
if !is_already_downloaded(&link, history)? {
|
||||||
|
@ -33,25 +28,6 @@ pub fn run(subscriptions: &str, history: &str, site: &str) -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_feed_url(site: &str, channel_name: &str) -> Result<String> {
|
|
||||||
if let Some(channel_prefix) = channel_name.chars().next() {
|
|
||||||
if channel_prefix != '@' {
|
|
||||||
return Err(format!("Channel Name must begin with an '@': {}", channel_name).into());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let channel_url = format!("{}{}", site, channel_name);
|
|
||||||
let response = reqwest::blocking::get(channel_url)?;
|
|
||||||
let rss_url = scraper::Html::parse_document(&response.text()?)
|
|
||||||
.select(&scraper::Selector::parse("link[title='RSS']").unwrap())
|
|
||||||
.next()
|
|
||||||
.unwrap()
|
|
||||||
.value()
|
|
||||||
.attr("href")
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
Ok(rss_url)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_link(item: &Entry) -> Option<Link> {
|
fn get_link(item: &Entry) -> Option<Link> {
|
||||||
item.links().get(0).cloned()
|
item.links().get(0).cloned()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
fn main() -> podal::Result<()> {
|
use podal::prelude::*;
|
||||||
|
|
||||||
|
fn main() -> Result<()> {
|
||||||
println!("Podal");
|
println!("Podal");
|
||||||
let subscriptions = "subscriptions.txt";
|
let subscriptions = "subscriptions.txt";
|
||||||
let history = "downloaded.txt";
|
let history = "downloaded.txt";
|
||||||
|
|
3
src/prelude.rs
Normal file
3
src/prelude.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
use crate::errors::Error;
|
||||||
|
|
||||||
|
pub type Result<T> = std::result::Result<T, Error>;
|
Loading…
Add table
Reference in a new issue