Still figuring out the schema.

This commit is contained in:
Jordan Petridis 2017-09-19 12:16:12 +03:00
parent a696e60f07
commit 91b314a81f
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
4 changed files with 30 additions and 17 deletions

View File

@ -21,7 +21,6 @@ CREATE TABLE `episode` (
CREATE TABLE `podcast` (
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
`title` TEXT NOT NULL UNIQUE,
`uri` TEXT NOT NULL UNIQUE,
`link` TEXT NOT NULL,
`description` TEXT NOT NULL,
`image_uri` TEXT,

View File

@ -30,7 +30,6 @@ pub struct Episode {
pub struct Podcast {
id: i32,
title: String,
uri: String,
link: String,
description: String,
image_uri: Option<String>,
@ -48,6 +47,22 @@ pub struct 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
pub fn get_podcast(&mut self) -> Result<NewPodcast> {
use std::io::Read;
@ -73,13 +88,16 @@ impl<'a> Source {
info!("Etag: {:?}", etag);
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.last_modified = lst_mod.map(|x| format!("{}", x));
info!("Self etag: {:?}", self.http_etag);
info!("Self last_mod: {:?}", self.last_modified);
// Maybe it would be better to just return 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)
}
@ -125,17 +143,18 @@ pub struct NewEpisode<'a> {
#[derive(Debug, Clone)]
pub struct NewPodcast {
pub title: String,
pub uri: String,
pub link: String,
pub description: String,
pub image_uri: Option<String>,
pub source_id: i32,
}
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 foo = ::parse_feeds::parse_podcast(&chan, uri)?;
let foo = ::parse_feeds::parse_podcast(&chan, parent.id())?;
Ok(foo)
}
}

View File

@ -2,7 +2,7 @@ use rss::{Channel, Item};
use models;
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 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 foo = models::NewPodcast {
uri: uri.to_owned(),
title,
link,
description,
image_uri,
source_id,
};
Ok(foo)
}
@ -80,13 +80,9 @@ mod tests {
// println!("{:#?}", channel);
let descr = "The people behind The Intercepts 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.uri,
"https://feeds.feedburner.com/InterceptedWithJeremyScahill".to_string()
);
assert_eq!(pd.link, "https://theintercept.com/podcasts".to_string());
assert_eq!(pd.description, descr.to_string());
assert_eq!(pd.image_uri, None);
@ -99,7 +95,7 @@ mod tests {
// 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 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.link, "http://www.jupiterbroadcasting.com/".to_string());
@ -119,7 +115,7 @@ mod tests {
// println!("{:#?}", channel);
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!(
pd.title,

View File

@ -17,7 +17,6 @@ table! {
podcast (id) {
id -> Integer,
title -> Text,
uri -> Text,
link -> Text,
description -> Text,
image_uri -> Nullable<Text>,