Still figuring out the schema.
This commit is contained in:
parent
a696e60f07
commit
91b314a81f
@ -21,7 +21,6 @@ CREATE TABLE `episode` (
|
|||||||
CREATE TABLE `podcast` (
|
CREATE TABLE `podcast` (
|
||||||
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||||
`title` TEXT NOT NULL UNIQUE,
|
`title` TEXT NOT NULL UNIQUE,
|
||||||
`uri` TEXT NOT NULL UNIQUE,
|
|
||||||
`link` TEXT NOT NULL,
|
`link` TEXT NOT NULL,
|
||||||
`description` TEXT NOT NULL,
|
`description` TEXT NOT NULL,
|
||||||
`image_uri` TEXT,
|
`image_uri` TEXT,
|
||||||
|
|||||||
@ -30,7 +30,6 @@ pub struct Episode {
|
|||||||
pub struct Podcast {
|
pub struct Podcast {
|
||||||
id: i32,
|
id: i32,
|
||||||
title: String,
|
title: String,
|
||||||
uri: String,
|
|
||||||
link: String,
|
link: String,
|
||||||
description: String,
|
description: String,
|
||||||
image_uri: Option<String>,
|
image_uri: Option<String>,
|
||||||
@ -48,6 +47,22 @@ pub struct Source {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Source {
|
impl<'a> Source {
|
||||||
|
pub fn id(&self) -> i32 {
|
||||||
|
self.id
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn uri(&self) -> &str {
|
||||||
|
&self.uri
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn last_modified(self) -> Option<String> {
|
||||||
|
self.last_modified
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn http_etag(self) -> Option<String> {
|
||||||
|
self.http_etag
|
||||||
|
}
|
||||||
|
|
||||||
// This is a mess
|
// This is a mess
|
||||||
pub fn get_podcast(&mut self) -> Result<NewPodcast> {
|
pub fn get_podcast(&mut self) -> Result<NewPodcast> {
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
@ -73,13 +88,16 @@ impl<'a> Source {
|
|||||||
info!("Etag: {:?}", etag);
|
info!("Etag: {:?}", etag);
|
||||||
info!("Last mod: {:?}", lst_mod);
|
info!("Last mod: {:?}", lst_mod);
|
||||||
|
|
||||||
|
// This is useless atm since theres no db passed to save the change
|
||||||
|
// but I needed to have it somewhere implemented for later.
|
||||||
self.http_etag = etag.map(|x| x.tag().to_string().to_owned());
|
self.http_etag = etag.map(|x| x.tag().to_string().to_owned());
|
||||||
self.last_modified = lst_mod.map(|x| format!("{}", x));
|
self.last_modified = lst_mod.map(|x| format!("{}", x));
|
||||||
info!("Self etag: {:?}", self.http_etag);
|
info!("Self etag: {:?}", self.http_etag);
|
||||||
info!("Self last_mod: {:?}", self.last_modified);
|
info!("Self last_mod: {:?}", self.last_modified);
|
||||||
|
|
||||||
|
// Maybe it would be better to just return buf
|
||||||
let chan = Channel::from_str(&buf)?;
|
let chan = Channel::from_str(&buf)?;
|
||||||
let foo = ::parse_feeds::parse_podcast(&chan, &self.uri)?;
|
let foo = ::parse_feeds::parse_podcast(&chan, self.id())?;
|
||||||
|
|
||||||
Ok(foo)
|
Ok(foo)
|
||||||
}
|
}
|
||||||
@ -125,17 +143,18 @@ pub struct NewEpisode<'a> {
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct NewPodcast {
|
pub struct NewPodcast {
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub uri: String,
|
|
||||||
pub link: String,
|
pub link: String,
|
||||||
pub description: String,
|
pub description: String,
|
||||||
pub image_uri: Option<String>,
|
pub image_uri: Option<String>,
|
||||||
|
pub source_id: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl<'a> NewPodcast {
|
impl<'a> NewPodcast {
|
||||||
pub fn from_url(uri: &'a str) -> Result<NewPodcast> {
|
// pub fn new(parent: &Source) {}
|
||||||
|
|
||||||
|
pub fn from_url(uri: &'a str, parent: &Source) -> Result<NewPodcast> {
|
||||||
let chan = Channel::from_url(uri)?;
|
let chan = Channel::from_url(uri)?;
|
||||||
let foo = ::parse_feeds::parse_podcast(&chan, uri)?;
|
let foo = ::parse_feeds::parse_podcast(&chan, parent.id())?;
|
||||||
Ok(foo)
|
Ok(foo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2,7 +2,7 @@ use rss::{Channel, Item};
|
|||||||
use models;
|
use models;
|
||||||
use errors::*;
|
use errors::*;
|
||||||
|
|
||||||
pub fn parse_podcast(chan: &Channel, uri: &str) -> Result<models::NewPodcast> {
|
pub fn parse_podcast(chan: &Channel, source_id: i32) -> Result<models::NewPodcast> {
|
||||||
|
|
||||||
let title = chan.title().to_owned();
|
let title = chan.title().to_owned();
|
||||||
let link = chan.link().to_owned();
|
let link = chan.link().to_owned();
|
||||||
@ -17,11 +17,11 @@ pub fn parse_podcast(chan: &Channel, uri: &str) -> Result<models::NewPodcast> {
|
|||||||
let image_uri = chan.image().map(|foo| foo.url().to_owned());
|
let image_uri = chan.image().map(|foo| foo.url().to_owned());
|
||||||
|
|
||||||
let foo = models::NewPodcast {
|
let foo = models::NewPodcast {
|
||||||
uri: uri.to_owned(),
|
|
||||||
title,
|
title,
|
||||||
link,
|
link,
|
||||||
description,
|
description,
|
||||||
image_uri,
|
image_uri,
|
||||||
|
source_id,
|
||||||
};
|
};
|
||||||
Ok(foo)
|
Ok(foo)
|
||||||
}
|
}
|
||||||
@ -80,13 +80,9 @@ mod tests {
|
|||||||
|
|
||||||
// println!("{:#?}", channel);
|
// println!("{:#?}", channel);
|
||||||
let descr = "The people behind The Intercept’s fearless reporting and incisive commentary—Jeremy Scahill, Glenn Greenwald, Betsy Reed and others—discuss the crucial issues of our time: national security, civil liberties, foreign policy, and criminal justice. Plus interviews with artists, thinkers, and newsmakers who challenge our preconceptions about the world we live in.";
|
let descr = "The people behind The Intercept’s fearless reporting and incisive commentary—Jeremy Scahill, Glenn Greenwald, Betsy Reed and others—discuss the crucial issues of our time: national security, civil liberties, foreign policy, and criminal justice. Plus interviews with artists, thinkers, and newsmakers who challenge our preconceptions about the world we live in.";
|
||||||
let pd = parse_podcast(&channel, uri).unwrap();
|
let pd = parse_podcast(&channel, 0).unwrap();
|
||||||
|
|
||||||
assert_eq!(pd.title, "Intercepted with Jeremy Scahill".to_string());
|
assert_eq!(pd.title, "Intercepted with Jeremy Scahill".to_string());
|
||||||
assert_eq!(
|
|
||||||
pd.uri,
|
|
||||||
"https://feeds.feedburner.com/InterceptedWithJeremyScahill".to_string()
|
|
||||||
);
|
|
||||||
assert_eq!(pd.link, "https://theintercept.com/podcasts".to_string());
|
assert_eq!(pd.link, "https://theintercept.com/podcasts".to_string());
|
||||||
assert_eq!(pd.description, descr.to_string());
|
assert_eq!(pd.description, descr.to_string());
|
||||||
assert_eq!(pd.image_uri, None);
|
assert_eq!(pd.image_uri, None);
|
||||||
@ -99,7 +95,7 @@ mod tests {
|
|||||||
|
|
||||||
// println!("{:#?}", channel);
|
// println!("{:#?}", channel);
|
||||||
let descr = "An open show powered by community LINUX Unplugged takes the best attributes of open collaboration and focuses them into a weekly lifestyle show about Linux.";
|
let descr = "An open show powered by community LINUX Unplugged takes the best attributes of open collaboration and focuses them into a weekly lifestyle show about Linux.";
|
||||||
let pd = parse_podcast(&channel, uri).unwrap();
|
let pd = parse_podcast(&channel, 0).unwrap();
|
||||||
|
|
||||||
assert_eq!(pd.title, "LINUX Unplugged Podcast".to_string());
|
assert_eq!(pd.title, "LINUX Unplugged Podcast".to_string());
|
||||||
assert_eq!(pd.link, "http://www.jupiterbroadcasting.com/".to_string());
|
assert_eq!(pd.link, "http://www.jupiterbroadcasting.com/".to_string());
|
||||||
@ -119,7 +115,7 @@ mod tests {
|
|||||||
|
|
||||||
// println!("{:#?}", channel);
|
// println!("{:#?}", channel);
|
||||||
let descr = "Latest Articles and Investigations from ProPublica, an independent, non-profit newsroom that produces investigative journalism in the public interest.";
|
let descr = "Latest Articles and Investigations from ProPublica, an independent, non-profit newsroom that produces investigative journalism in the public interest.";
|
||||||
let pd = parse_podcast(&channel, uri).unwrap();
|
let pd = parse_podcast(&channel, 0).unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
pd.title,
|
pd.title,
|
||||||
|
|||||||
@ -17,7 +17,6 @@ table! {
|
|||||||
podcast (id) {
|
podcast (id) {
|
||||||
id -> Integer,
|
id -> Integer,
|
||||||
title -> Text,
|
title -> Text,
|
||||||
uri -> Text,
|
|
||||||
link -> Text,
|
link -> Text,
|
||||||
description -> Text,
|
description -> Text,
|
||||||
image_uri -> Nullable<Text>,
|
image_uri -> Nullable<Text>,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user