Finally getting somewhere.
This commit is contained in:
parent
91b314a81f
commit
159ac4cd5d
@ -12,8 +12,8 @@ CREATE TABLE `episode` (
|
|||||||
`local_uri` TEXT,
|
`local_uri` TEXT,
|
||||||
`description` TEXT,
|
`description` TEXT,
|
||||||
`published_date` TEXT NOT NULL,
|
`published_date` TEXT NOT NULL,
|
||||||
`epoch` INTEGER NOT NULL DEFAULT 0,
|
`epoch` INTEGER NOT NULL,
|
||||||
`length` INTEGER DEFAULT 0,
|
`length` INTEGER,
|
||||||
`guid` TEXT,
|
`guid` TEXT,
|
||||||
`podcast_id` INTEGER NOT NULL
|
`podcast_id` INTEGER NOT NULL
|
||||||
);
|
);
|
||||||
|
|||||||
@ -13,7 +13,6 @@ pub fn get_pd_episodes(con: &SqliteConnection, parent: &Podcast) -> QueryResult<
|
|||||||
eps
|
eps
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn get_sources(con: &SqliteConnection) -> QueryResult<Vec<Source>>{
|
pub fn get_sources(con: &SqliteConnection) -> QueryResult<Vec<Source>>{
|
||||||
let s = source.load::<Source>(con);
|
let s = source.load::<Source>(con);
|
||||||
s
|
s
|
||||||
|
|||||||
@ -3,7 +3,7 @@ use diesel;
|
|||||||
use schema;
|
use schema;
|
||||||
use dbqueries;
|
use dbqueries;
|
||||||
use errors::*;
|
use errors::*;
|
||||||
use models::{NewPodcast, NewSource};
|
use models::{NewPodcast, NewSource, Source};
|
||||||
|
|
||||||
pub fn foo() {
|
pub fn foo() {
|
||||||
let inpt = vec![
|
let inpt = vec![
|
||||||
@ -24,8 +24,7 @@ pub fn foo() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let f = dbqueries::get_sources(&db);
|
index_loop(db);
|
||||||
info!("{:?}", f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insert_source(connection: &SqliteConnection, url: &str) -> Result<()> {
|
fn insert_source(connection: &SqliteConnection, url: &str) -> Result<()> {
|
||||||
@ -37,3 +36,23 @@ fn insert_source(connection: &SqliteConnection, url: &str) -> Result<()> {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub fn index_loop(db: SqliteConnection) -> Result<()> {
|
||||||
|
// let db = ::establish_connection();
|
||||||
|
use parse_feeds;
|
||||||
|
|
||||||
|
let f = dbqueries::get_sources(&db);
|
||||||
|
|
||||||
|
for feed in f.unwrap().iter_mut() {
|
||||||
|
info!("{:?}", feed.id());
|
||||||
|
// This method will defently get split and nuked
|
||||||
|
// but for now its poc
|
||||||
|
let chan = feed.get_podcast_chan(&db)?;
|
||||||
|
let pd = parse_feeds::parse_podcast(&chan, feed.id())?;
|
||||||
|
info!("{:#?}", pd);
|
||||||
|
// info!("{:?}", chan);
|
||||||
|
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@ -1,5 +1,8 @@
|
|||||||
use reqwest;
|
use reqwest;
|
||||||
use rss::Channel;
|
use rss::Channel;
|
||||||
|
use diesel::SaveChangesDsl;
|
||||||
|
use SqliteConnection;
|
||||||
|
use reqwest::header::{ETag, LastModified};
|
||||||
|
|
||||||
use schema::{episode, podcast, source};
|
use schema::{episode, podcast, source};
|
||||||
use errors::*;
|
use errors::*;
|
||||||
@ -63,10 +66,10 @@ impl<'a> Source {
|
|||||||
self.http_etag
|
self.http_etag
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is a mess
|
/// Fetch the xml feed from the source url, update the etag headers,
|
||||||
pub fn get_podcast(&mut self) -> Result<NewPodcast> {
|
/// and parse the feed into an rss:Channel and return it.
|
||||||
|
pub fn get_podcast_chan(&mut self, con: &SqliteConnection) -> Result<Channel> {
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use reqwest::header::*;
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
let mut req = reqwest::get(&self.uri)?;
|
let mut req = reqwest::get(&self.uri)?;
|
||||||
@ -78,28 +81,31 @@ impl<'a> Source {
|
|||||||
let headers = req.headers();
|
let headers = req.headers();
|
||||||
debug!("{:#?}", headers);
|
debug!("{:#?}", headers);
|
||||||
|
|
||||||
// for h in headers.iter() {
|
|
||||||
// info!("{}: {}", h.name(), h.value_string());
|
|
||||||
// }
|
|
||||||
|
|
||||||
// let etag = headers.get_raw("ETag").unwrap();
|
// let etag = headers.get_raw("ETag").unwrap();
|
||||||
let etag = headers.get::<ETag>();
|
let etag = headers.get::<ETag>();
|
||||||
let lst_mod = headers.get::<LastModified>();
|
let lst_mod = headers.get::<LastModified>();
|
||||||
info!("Etag: {:?}", etag);
|
self.update(con, etag, lst_mod)?;
|
||||||
info!("Last mod: {:?}", lst_mod);
|
|
||||||
|
let chan = Channel::from_str(&buf)?;
|
||||||
|
// let foo = ::parse_feeds::parse_podcast(&chan, self.id())?;
|
||||||
|
|
||||||
|
Ok(chan)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update(
|
||||||
|
&mut self,
|
||||||
|
con: &SqliteConnection,
|
||||||
|
etag: Option<&ETag>,
|
||||||
|
lmod: Option<&LastModified>,
|
||||||
|
) -> Result<()> {
|
||||||
|
|
||||||
// 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 = lmod.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
|
self.save_changes::<Source>(con)?;
|
||||||
let chan = Channel::from_str(&buf)?;
|
Ok(())
|
||||||
let foo = ::parse_feeds::parse_podcast(&chan, self.id())?;
|
|
||||||
|
|
||||||
Ok(foo)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user