extract feed::get
This commit is contained in:
parent
507447f6ad
commit
0b6903404a
3 changed files with 13 additions and 9 deletions
9
src/feed/get.rs
Normal file
9
src/feed/get.rs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
use atom_syndication::Feed;
|
||||||
|
|
||||||
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
pub fn get_feed(url: String) -> Result<Feed> {
|
||||||
|
let content = reqwest::blocking::get(url)?.bytes()?;
|
||||||
|
let channel = Feed::read_from(&content[..])?;
|
||||||
|
Ok(channel)
|
||||||
|
}
|
|
@ -1,3 +1,5 @@
|
||||||
mod find;
|
mod find;
|
||||||
|
mod get;
|
||||||
|
|
||||||
pub use find::get_feed_url;
|
pub use find::get_feed_url;
|
||||||
|
pub use get::get_feed;
|
||||||
|
|
11
src/lib.rs
11
src/lib.rs
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
|
||||||
use atom_syndication::{Entry, Feed, Link};
|
use atom_syndication::{Entry, Link};
|
||||||
|
|
||||||
mod errors;
|
mod errors;
|
||||||
mod feed;
|
mod feed;
|
||||||
|
@ -15,7 +15,7 @@ pub fn run(subscriptions: &str, history: &str, site: &str) -> Result<()> {
|
||||||
let channel_name = channel_name?;
|
let channel_name = channel_name?;
|
||||||
println!("Channel: {}", channel_name);
|
println!("Channel: {}", channel_name);
|
||||||
let feed_url = feed::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 feed::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)? {
|
||||||
println!("Downloading {}: {}", &channel_name, entry.title().as_str());
|
println!("Downloading {}: {}", &channel_name, entry.title().as_str());
|
||||||
|
@ -41,13 +41,6 @@ fn lines_from(file_name: &str) -> Result<std::io::Lines<std::io::BufReader<std::
|
||||||
Ok(reader.lines())
|
Ok(reader.lines())
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetch the RSS feed
|
|
||||||
fn get_feed(url: String) -> Result<Feed> {
|
|
||||||
let content = reqwest::blocking::get(url)?.bytes()?;
|
|
||||||
let channel = Feed::read_from(&content[..])?;
|
|
||||||
Ok(channel)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_already_downloaded(link: &Link, file_name: &str) -> Result<bool> {
|
fn is_already_downloaded(link: &Link, file_name: &str) -> Result<bool> {
|
||||||
use std::io::{BufRead, BufReader};
|
use std::io::{BufRead, BufReader};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue