Extended parse_podcast_test and implemented parse_podcast.
This commit is contained in:
parent
dcd5a8dcb7
commit
dbe606f5d5
@ -18,6 +18,5 @@ CREATE TABLE `podcast` (
|
||||
`description` TEXT,
|
||||
`last_modified` TEXT,
|
||||
`http_etag` TEXT,
|
||||
`image_uri` TEXT,
|
||||
`image_local` TEXT
|
||||
`image_uri` TEXT
|
||||
);
|
||||
@ -29,7 +29,6 @@ pub struct Podcast {
|
||||
last_modified: Option<String>,
|
||||
http_etag: Option<String>,
|
||||
image_uri: Option<String>,
|
||||
image_local: Option<String>,
|
||||
}
|
||||
|
||||
|
||||
@ -58,5 +57,4 @@ pub struct NewPodcast<'a> {
|
||||
pub last_modified: Option<&'a str>,
|
||||
pub http_etag: Option<&'a str>,
|
||||
pub image_uri: Option<&'a str>,
|
||||
pub image_local: Option<&'a str>,
|
||||
}
|
||||
@ -1,22 +1,32 @@
|
||||
use rss::Channel;
|
||||
use models;
|
||||
|
||||
pub fn parse_podcast<'a>(podcast_chan: Channel) -> models::NewPodcast<'a> {
|
||||
pub fn parse_podcast<'a>(pd_chan: &'a Channel, uri: &'a str) -> models::NewPodcast<'a> {
|
||||
let title = pd_chan.title();
|
||||
|
||||
let foo = models::NewPodcast {
|
||||
title: "foo",
|
||||
uri: "foo",
|
||||
link: Some("foo"),
|
||||
description: Some("foo"),
|
||||
// need to get it from reqwest probably
|
||||
// I dont think uri can be consinstantly infered from the Channel
|
||||
// TODO: Add etag support
|
||||
let last_modified = None;
|
||||
let http_etag = None;
|
||||
|
||||
// need to get it from reqwest probably
|
||||
last_modified: Some("foo"),
|
||||
http_etag: Some("foo"),
|
||||
let link = Some(pd_chan.link());
|
||||
let description = Some(pd_chan.description());
|
||||
|
||||
image_uri: Some("foo"),
|
||||
image_local: Some("foo"),
|
||||
let image_uri = match pd_chan.image() {
|
||||
Some(foo) => Some(foo.url()),
|
||||
None => None,
|
||||
};
|
||||
foo
|
||||
|
||||
models::NewPodcast {
|
||||
title,
|
||||
uri,
|
||||
link,
|
||||
description,
|
||||
last_modified,
|
||||
http_etag,
|
||||
image_uri,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -28,28 +38,64 @@ mod tests {
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
assert_eq!(2 + 2, 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_podcast() {
|
||||
// Intercepted feed
|
||||
let file = File::open("tests/feeds/Intercepted.xml").unwrap();
|
||||
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
||||
let uri = "https://feeds.feedburner.com/InterceptedWithJeremyScahill";
|
||||
|
||||
// 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 pd = parse_podcast(channel);
|
||||
let pd = parse_podcast(&channel, uri);
|
||||
|
||||
assert_eq!(pd.title, "Intercepted with Jeremy Scahill");
|
||||
// assert_eq!(
|
||||
// pd.uri,
|
||||
// "https://feeds.feedburner.com/InterceptedWithJeremyScahill"
|
||||
// );
|
||||
assert_eq!(pd.link, Some("https://theintercept.com/podcasts"));
|
||||
assert_eq!(pd.description, Some(descr));
|
||||
assert_eq!(pd.last_modified, None);
|
||||
assert_eq!(pd.http_etag, None);
|
||||
assert_eq!(pd.image_uri, None);
|
||||
assert_eq!(pd.image_local, None);
|
||||
|
||||
|
||||
// Linux Unplugged Feed
|
||||
let file = File::open("tests/feeds/LinuxUnplugged.xml").unwrap();
|
||||
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
||||
let uri = "http://feeds.feedburner.com/linuxunplugged";
|
||||
|
||||
// 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);
|
||||
|
||||
assert_eq!(pd.title, "LINUX Unplugged Podcast");
|
||||
assert_eq!(pd.link, Some("http://www.jupiterbroadcasting.com/"));
|
||||
assert_eq!(pd.description, Some(descr));
|
||||
assert_eq!(pd.last_modified, None);
|
||||
assert_eq!(pd.http_etag, None);
|
||||
assert_eq!(
|
||||
pd.image_uri,
|
||||
Some("http://michaeltunnell.com/images/linux-unplugged.jpg")
|
||||
);
|
||||
|
||||
|
||||
// The Breakthrough Feed
|
||||
let file = File::open("tests/feeds/TheBreakthrough.xml").unwrap();
|
||||
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
||||
let uri = "http://feeds.propublica.org/propublica/main";
|
||||
|
||||
// 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);
|
||||
|
||||
assert_eq!(pd.title, "Articles and Investigations - ProPublica");
|
||||
assert_eq!(pd.link, Some("https://www.propublica.org/feeds/54Ghome"));
|
||||
assert_eq!(pd.description, Some(descr));
|
||||
assert_eq!(pd.last_modified, None);
|
||||
assert_eq!(pd.http_etag, None);
|
||||
assert_eq!(pd.image_uri, Some("https://assets.propublica.org/propublica-rss-logo.png"));
|
||||
}
|
||||
|
||||
}
|
||||
@ -22,6 +22,5 @@ table! {
|
||||
last_modified -> Nullable<Text>,
|
||||
http_etag -> Nullable<Text>,
|
||||
image_uri -> Nullable<Text>,
|
||||
image_local -> Nullable<Text>,
|
||||
}
|
||||
}
|
||||
|
||||
4082
tests/feeds/LinuxUnplugged.xml
Normal file
4082
tests/feeds/LinuxUnplugged.xml
Normal file
File diff suppressed because it is too large
Load Diff
1378
tests/feeds/TheBreakthrough.xml
Normal file
1378
tests/feeds/TheBreakthrough.xml
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user