diff --git a/migrations/2017-09-15-001128_init_schema/up.sql b/migrations/2017-09-15-001128_init_schema/up.sql index ca5928a..559e2ea 100644 --- a/migrations/2017-09-15-001128_init_schema/up.sql +++ b/migrations/2017-09-15-001128_init_schema/up.sql @@ -7,12 +7,12 @@ CREATE TABLE `source` ( CREATE TABLE `episode` ( `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, - `title` TEXT NOT NULL, - `uri` TEXT NOT NULL, + `title` TEXT, + `uri` TEXT, `local_uri` TEXT, `description` TEXT, - `published_date` TEXT NOT NULL, - `epoch` INTEGER NOT NULL, + `published_date` TEXT , + `epoch` INTEGER, `length` INTEGER, `guid` TEXT, `podcast_id` INTEGER NOT NULL diff --git a/src/index_feed.rs b/src/index_feed.rs index db1de71..5b7ce7a 100644 --- a/src/index_feed.rs +++ b/src/index_feed.rs @@ -24,7 +24,7 @@ pub fn foo() { } } - index_loop(db); + index_loop(db).unwrap(); } fn insert_source(connection: &SqliteConnection, url: &str) -> Result<()> { @@ -50,7 +50,15 @@ pub fn index_loop(db: SqliteConnection) -> Result<()> { // but for now its poc let chan = feed.get_podcast_chan(&db)?; let pd = parse_feeds::parse_podcast(&chan, feed.id())?; + + // Holy shit this works! + let episodes: Vec<_> = chan.items() + .iter() + .map(|x| parse_feeds::parse_episode(x, feed.id())) + .collect(); + info!("{:#?}", pd); + info!("{:#?}", episodes); // info!("{:?}", chan); } diff --git a/src/models.rs b/src/models.rs index d2524a0..d04c1fb 100644 --- a/src/models.rs +++ b/src/models.rs @@ -14,12 +14,12 @@ use errors::*; #[derive(Debug, Clone)] pub struct Episode { id: i32, - title: String, - uri: String, + title: Option, + uri: Option, local_uri: Option, description: Option, - published_date: String, - epoch: i32, + published_date: Option, + epoch: Option, length: Option, guid: Option, podcast_id: i32, @@ -133,11 +133,11 @@ impl<'a> NewSource<'a> { #[table_name = "episode"] #[derive(Debug, Clone)] pub struct NewEpisode<'a> { - pub title: &'a str, - pub uri: &'a str, + pub title: Option<&'a str>, + pub uri: Option<&'a str>, pub local_uri: Option<&'a str>, pub description: Option<&'a str>, - pub published_date: &'a str, + pub published_date: Option<&'a str>, pub length: Option, pub guid: Option<&'a str>, pub epoch: i32, diff --git a/src/parse_feeds.rs b/src/parse_feeds.rs index 176e8a9..ae54a89 100644 --- a/src/parse_feeds.rs +++ b/src/parse_feeds.rs @@ -29,24 +29,25 @@ pub fn parse_podcast(chan: &Channel, source_id: i32) -> Result(item: &'a Item, parent_id: i32) -> Result> { - let title = item.title().unwrap(); + let title = item.title().map(|x| x); - let description = item.description(); - let guid = Some(item.guid().unwrap().value()); + let description = item.description().map(|x| x); + let guid = item.guid().map(|x| x.value()); - let uri = item.enclosure().unwrap().url(); + let uri = item.enclosure().map(|x| x.url()); // FIXME: // probably needs to be removed from NewEpisode, // and have seperate logic to handle local_files let local_uri = None; - let pub_date = item.pub_date().unwrap(); + let pub_date = item.pub_date().map(|x| x); // FIXME: parse pub_date to epoch later let epoch = 0; - let length = Some(item.enclosure().unwrap().length().parse().unwrap()); + // let length = Some(item.enclosure().unwrap().length().parse().unwrap()); + let length = item.enclosure().map(|x| x.length().parse().unwrap()); let foo = models::NewEpisode { title, @@ -144,12 +145,15 @@ mod tests { // println!("{:#?}", firstitem); let it = parse_episode(&firstitem, 0).unwrap(); - assert_eq!(it.title, "The Super Bowl of Racism"); - assert_eq!(it.uri, "http://traffic.megaphone.fm/PPY6458293736.mp3"); + assert_eq!(it.title, Some("The Super Bowl of Racism")); + assert_eq!( + it.uri, + Some("http://traffic.megaphone.fm/PPY6458293736.mp3") + ); assert_eq!(it.description, Some(descr)); assert_eq!(it.length, Some(66738886)); assert_eq!(it.guid, Some("7df4070a-9832-11e7-adac-cb37b05d5e24")); - assert_eq!(it.published_date, "Wed, 13 Sep 2017 10:00:00 -0000"); + assert_eq!(it.published_date, Some("Wed, 13 Sep 2017 10:00:00 -0000")); let second = channel.items().iter().nth(1).unwrap(); // println!("{:#?}", second); @@ -158,13 +162,15 @@ mod tests { let descr = "This week on Intercepted: Jeremy gives an update on the aftermath of Blackwater’s 2007 massacre of Iraqi civilians. Intercept reporter Lee Fang lays out how a network of libertarian think tanks called the Atlas Network is insidiously shaping political infrastructure in Latin America. We speak with attorney and former Hugo Chavez adviser Eva Golinger about the Venezuela\'s political turmoil.And we hear Claudia Lizardo of the Caracas-based band, La Pequeña Revancha, talk about her music and hopes for Venezuela."; assert_eq!( i2.title, - "Atlas Golfed — U.S.-Backed Think Tanks Target Latin America" + Some( + "Atlas Golfed — U.S.-Backed Think Tanks Target Latin America", + ) ); - assert_eq!(i2.uri, "http://traffic.megaphone.fm/FL5331443769.mp3"); + assert_eq!(i2.uri, Some("http://traffic.megaphone.fm/FL5331443769.mp3")); assert_eq!(i2.description, Some(descr)); assert_eq!(i2.length, Some(67527575)); assert_eq!(i2.guid, Some("7c207a24-e33f-11e6-9438-eb45dcf36a1d")); - assert_eq!(i2.published_date, "Wed, 09 Aug 2017 10:00:00 -0000"); + assert_eq!(i2.published_date, Some("Wed, 09 Aug 2017 10:00:00 -0000")); } } \ No newline at end of file diff --git a/src/schema.rs b/src/schema.rs index 868f85f..3cdb9e6 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -1,12 +1,12 @@ table! { episode (id) { id -> Integer, - title -> Text, - uri -> Text, + title -> Nullable, + uri -> Nullable, local_uri -> Nullable, description -> Nullable, - published_date -> Text, - epoch -> Integer, + published_date -> Nullable, + epoch -> Nullable, length -> Nullable, guid -> Nullable, podcast_id -> Integer,