remove FeedEnv
This commit is contained in:
parent
f211823884
commit
95ed1735e7
7 changed files with 10 additions and 37 deletions
|
@ -7,12 +7,6 @@ mod find;
|
||||||
|
|
||||||
pub use find::find;
|
pub use find::find;
|
||||||
|
|
||||||
pub struct FeedEnv {
|
|
||||||
pub find: FeedFind,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type FeedFind = fn(&str, &str, &NetworkEnv) -> Result<String>;
|
|
||||||
|
|
||||||
pub fn get(url: &str, e: &NetworkEnv) -> Result<Feed> {
|
pub fn get(url: &str, e: &NetworkEnv) -> Result<Feed> {
|
||||||
let content = (e.fetch_as_bytes)(url)?;
|
let content = (e.fetch_as_bytes)(url)?;
|
||||||
let channel = Feed::read_from(&content[..])?;
|
let channel = Feed::read_from(&content[..])?;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::prelude::*;
|
use crate::{history::Link, prelude::*};
|
||||||
|
|
||||||
use atom_syndication::Link;
|
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
pub struct FetchEnv {
|
pub struct FetchEnv {
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
use atom_syndication::Link;
|
|
||||||
use std::fs::OpenOptions;
|
use std::fs::OpenOptions;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
|
|
||||||
|
use super::Link;
|
||||||
|
|
||||||
pub fn add(link: &Link, file_name: &str) -> Result<()> {
|
pub fn add(link: &Link, file_name: &str) -> Result<()> {
|
||||||
let mut file = OpenOptions::new()
|
let mut file = OpenOptions::new()
|
||||||
.write(true)
|
.write(true)
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
use crate::{file::FileEnv, prelude::*};
|
use crate::{file::FileEnv, prelude::*};
|
||||||
|
|
||||||
use atom_syndication::Link;
|
|
||||||
use std::io::{BufRead, BufReader};
|
use std::io::{BufRead, BufReader};
|
||||||
|
|
||||||
|
use super::Link;
|
||||||
|
|
||||||
pub fn find(link: &Link, file_name: &str, e: &FileEnv) -> Result<bool> {
|
pub fn find(link: &Link, file_name: &str, e: &FileEnv) -> Result<bool> {
|
||||||
if let Ok(file) = (e.open)(file_name) {
|
if let Ok(file) = (e.open)(file_name) {
|
||||||
let reader = BufReader::new(file);
|
let reader = BufReader::new(file);
|
||||||
|
|
|
@ -1,17 +1,7 @@
|
||||||
use crate::{file::FileEnv, prelude::*};
|
|
||||||
|
|
||||||
mod add;
|
mod add;
|
||||||
mod find;
|
mod find;
|
||||||
|
|
||||||
pub use add::add;
|
pub use add::add;
|
||||||
pub use find::find;
|
pub use find::find;
|
||||||
|
|
||||||
type Link = atom_syndication::Link;
|
pub type Link = atom_syndication::Link;
|
||||||
|
|
||||||
pub struct HistoryEnv {
|
|
||||||
pub find: HistoryFind,
|
|
||||||
pub add: HistoryAdd,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type HistoryFind = fn(&Link, &str, &FileEnv) -> Result<bool>;
|
|
||||||
pub type HistoryAdd = fn(&Link, &str) -> Result<()>;
|
|
||||||
|
|
10
src/lib.rs
10
src/lib.rs
|
@ -9,17 +9,13 @@ pub mod prelude;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test_utils;
|
mod test_utils;
|
||||||
|
|
||||||
use feed::FeedEnv;
|
|
||||||
use fetch::FetchEnv;
|
use fetch::FetchEnv;
|
||||||
use file::FileEnv;
|
use file::FileEnv;
|
||||||
use history::HistoryEnv;
|
|
||||||
use network::NetworkEnv;
|
use network::NetworkEnv;
|
||||||
use prelude::*;
|
use prelude::*;
|
||||||
|
|
||||||
pub struct Env {
|
pub struct Env {
|
||||||
pub feed: FeedEnv,
|
|
||||||
pub network: NetworkEnv,
|
pub network: NetworkEnv,
|
||||||
pub history: HistoryEnv,
|
|
||||||
pub fetch: FetchEnv,
|
pub fetch: FetchEnv,
|
||||||
pub file: FileEnv,
|
pub file: FileEnv,
|
||||||
}
|
}
|
||||||
|
@ -27,13 +23,13 @@ pub struct Env {
|
||||||
pub fn run(subscriptions: &str, history: &str, site: &str, e: Env) -> Result<()> {
|
pub fn run(subscriptions: &str, history: &str, site: &str, e: Env) -> Result<()> {
|
||||||
for channel_name in file::read::lines_from(subscriptions, &e.file)? {
|
for channel_name in file::read::lines_from(subscriptions, &e.file)? {
|
||||||
println!("Channel: {}", channel_name);
|
println!("Channel: {}", channel_name);
|
||||||
let feed_url = (e.feed.find)(site, &channel_name, &e.network)?;
|
let feed_url = feed::find(site, &channel_name, &e.network)?;
|
||||||
for entry in feed::get(&feed_url, &e.network)?.entries() {
|
for entry in feed::get(&feed_url, &e.network)?.entries() {
|
||||||
if let Some(link) = entry.links().get(0).cloned() {
|
if let Some(link) = entry.links().get(0).cloned() {
|
||||||
if !(e.history.find)(&link, history, &e.file)? {
|
if !history::find(&link, history, &e.file)? {
|
||||||
println!("Downloading {}: {}", &channel_name, entry.title().as_str());
|
println!("Downloading {}: {}", &channel_name, entry.title().as_str());
|
||||||
(e.fetch.download)(&link)?;
|
(e.fetch.download)(&link)?;
|
||||||
(e.history.add)(&link, history)?;
|
history::add(&link, history)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -2,7 +2,7 @@ use podal::file::FileEnv;
|
||||||
use podal::network::NetworkEnv;
|
use podal::network::NetworkEnv;
|
||||||
use podal::prelude::*;
|
use podal::prelude::*;
|
||||||
|
|
||||||
use podal::{feed::FeedEnv, fetch::FetchEnv, history::HistoryEnv};
|
use podal::fetch::FetchEnv;
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
println!("Podal");
|
println!("Podal");
|
||||||
|
@ -15,14 +15,6 @@ fn main() -> Result<()> {
|
||||||
history,
|
history,
|
||||||
site,
|
site,
|
||||||
podal::Env {
|
podal::Env {
|
||||||
feed: FeedEnv {
|
|
||||||
find: podal::feed::find,
|
|
||||||
},
|
|
||||||
|
|
||||||
history: HistoryEnv {
|
|
||||||
find: podal::history::find,
|
|
||||||
add: podal::history::add,
|
|
||||||
},
|
|
||||||
fetch: FetchEnv {
|
fetch: FetchEnv {
|
||||||
download: podal::fetch::download,
|
download: podal::fetch::download,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Reference in a new issue