I dont even know at this point.
This commit is contained in:
parent
fe2d8c8b52
commit
a696e60f07
@ -20,8 +20,8 @@ CREATE TABLE `episode` (
|
||||
|
||||
CREATE TABLE `podcast` (
|
||||
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||
`title` TEXT NOT NULL,
|
||||
`uri` TEXT UNIQUE NOT NULL,
|
||||
`title` TEXT NOT NULL UNIQUE,
|
||||
`uri` TEXT NOT NULL UNIQUE,
|
||||
`link` TEXT NOT NULL,
|
||||
`description` TEXT NOT NULL,
|
||||
`image_uri` TEXT,
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use structopt::StructOpt;
|
||||
use loggerv;
|
||||
use errors::*;
|
||||
use models::NewPodcast;
|
||||
// use models::NewPodcast;
|
||||
|
||||
#[derive(StructOpt, Debug)]
|
||||
#[structopt(name = "example", about = "An example of StructOpt usage.")]
|
||||
@ -20,8 +20,7 @@ pub fn run() -> Result<()> {
|
||||
info!("{:?}", foo);
|
||||
|
||||
::init()?;
|
||||
// ::parse_feeds::foo();
|
||||
// ::index_feed::foo();
|
||||
::index_feed::foo();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -1,10 +1,9 @@
|
||||
use diesel::prelude::*;
|
||||
use schema::podcast::dsl::*;
|
||||
// use schema::episode::dsl::*;
|
||||
use models::{Podcast, Episode};
|
||||
use schema::source::dsl::*;
|
||||
use models::{Podcast, Episode, Source};
|
||||
|
||||
pub fn get_podcasts(con: &SqliteConnection) -> QueryResult<Vec<Podcast>> {
|
||||
let pds = podcast.load::<Podcast>(con);
|
||||
pub fn get_podcasts(con: &SqliteConnection, parent: &Source) -> QueryResult<Vec<Podcast>> {
|
||||
let pds = Podcast::belonging_to(parent).load::<Podcast>(con);
|
||||
// debug!("Returned Podcasts:\n{:?}", pds);
|
||||
pds
|
||||
}
|
||||
@ -13,4 +12,9 @@ pub fn get_pd_episodes(con: &SqliteConnection, parent: &Podcast) -> QueryResult<
|
||||
let eps = Episode::belonging_to(parent).load::<Episode>(con);
|
||||
eps
|
||||
}
|
||||
|
||||
|
||||
|
||||
pub fn get_sources(con: &SqliteConnection) -> QueryResult<Vec<Source>>{
|
||||
let s = source.load::<Source>(con);
|
||||
s
|
||||
}
|
||||
@ -1,10 +1,9 @@
|
||||
use diesel::prelude::*;
|
||||
use diesel;
|
||||
use rss::Channel;
|
||||
use schema;
|
||||
use dbqueries;
|
||||
use errors::*;
|
||||
use models::NewPodcast;
|
||||
use models::{NewPodcast, NewSource};
|
||||
|
||||
pub fn foo() {
|
||||
let inpt = vec![
|
||||
@ -15,7 +14,7 @@ pub fn foo() {
|
||||
|
||||
let db = ::establish_connection();
|
||||
for feed in inpt.iter() {
|
||||
match insert_feed(&db, feed) {
|
||||
match insert_source(&db, feed) {
|
||||
Ok(_) => {}
|
||||
Err(foo) => {
|
||||
debug!("Error: {}", foo);
|
||||
@ -24,26 +23,17 @@ pub fn foo() {
|
||||
}
|
||||
}
|
||||
}
|
||||
update_podcasts(&db);
|
||||
|
||||
let f = dbqueries::get_sources(&db);
|
||||
info!("{:?}", f);
|
||||
}
|
||||
|
||||
fn insert_feed(connection: &SqliteConnection, url: &str) -> Result<()> {
|
||||
let foo = NewPodcast::from_url(url)?;
|
||||
fn insert_source(connection: &SqliteConnection, url: &str) -> Result<()> {
|
||||
let foo = NewSource::new_with_uri(url);
|
||||
|
||||
diesel::insert(&foo).into(schema::podcast::table).execute(
|
||||
diesel::insert(&foo).into(schema::source::table).execute(
|
||||
connection,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
fn update_podcasts(connection: &SqliteConnection) {
|
||||
let pds = dbqueries::get_podcasts(connection).unwrap();
|
||||
info!("{:?}", pds);
|
||||
|
||||
// for pd in pds {
|
||||
// println!("{:?}" pd.uri);
|
||||
// }
|
||||
|
||||
}
|
||||
@ -37,7 +37,7 @@ pub struct Podcast {
|
||||
source_id: i32,
|
||||
}
|
||||
|
||||
#[derive(Queryable, Identifiable)]
|
||||
#[derive(Queryable, Identifiable, AsChangeset)]
|
||||
#[table_name = "source"]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Source {
|
||||
@ -47,6 +47,45 @@ pub struct Source {
|
||||
http_etag: Option<String>,
|
||||
}
|
||||
|
||||
impl<'a> Source {
|
||||
// This is a mess
|
||||
pub fn get_podcast(&mut self) -> Result<NewPodcast> {
|
||||
use std::io::Read;
|
||||
use reqwest::header::*;
|
||||
use std::str::FromStr;
|
||||
|
||||
let mut req = reqwest::get(&self.uri)?;
|
||||
|
||||
let mut buf = String::new();
|
||||
req.read_to_string(&mut buf)?;
|
||||
// info!("{}", buf);
|
||||
|
||||
let headers = req.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::<ETag>();
|
||||
let lst_mod = headers.get::<LastModified>();
|
||||
info!("Etag: {:?}", etag);
|
||||
info!("Last mod: {:?}", lst_mod);
|
||||
|
||||
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);
|
||||
|
||||
let chan = Channel::from_str(&buf)?;
|
||||
let foo = ::parse_feeds::parse_podcast(&chan, &self.uri)?;
|
||||
|
||||
Ok(foo)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Remove pub fields and add setters.
|
||||
#[derive(Insertable)]
|
||||
#[table_name = "source"]
|
||||
#[derive(Debug, Clone)]
|
||||
@ -56,6 +95,16 @@ pub struct NewSource<'a> {
|
||||
pub http_etag: Option<&'a str>,
|
||||
}
|
||||
|
||||
impl<'a> NewSource<'a> {
|
||||
pub fn new_with_uri(uri: &'a str) -> NewSource {
|
||||
NewSource {
|
||||
uri,
|
||||
last_modified: None,
|
||||
http_etag: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Insertable)]
|
||||
#[table_name = "episode"]
|
||||
#[derive(Debug, Clone)]
|
||||
@ -89,39 +138,4 @@ impl<'a> NewPodcast {
|
||||
let foo = ::parse_feeds::parse_podcast(&chan, uri)?;
|
||||
Ok(foo)
|
||||
}
|
||||
|
||||
// Ignore this atm
|
||||
// pub fn from_url(uri: &str) -> Result<()> {
|
||||
|
||||
// use std::io::Read;
|
||||
// use reqwest::header::*;
|
||||
// use std::str::FromStr;
|
||||
// use parse_feeds;
|
||||
|
||||
// let mut req = reqwest::get(uri)?;
|
||||
|
||||
// let mut buf = String::new();
|
||||
// req.read_to_string(&mut buf)?;
|
||||
// info!("{}", buf);
|
||||
|
||||
// let headers = req.headers();
|
||||
// info!("{:#?}", headers);
|
||||
|
||||
// // for h in headers.iter() {
|
||||
// // info!("{}: {}", h.name(), h.value_string());
|
||||
// // }
|
||||
|
||||
// // Sometimes dsnt work
|
||||
// // let etag = headers.get::<ETag>();
|
||||
// let etag = headers.get_raw("ETag").unwrap();
|
||||
// let lst_mod = headers.get::<LastModified>().unwrap();
|
||||
// info!("Etag: {:?}", etag);
|
||||
// info!("Last mod: {}", lst_mod);
|
||||
|
||||
// let pd_chan = Channel::from_str(buf.as_str())?;
|
||||
// // let bar = parse_feeds::parse_podcast(&foo)?;
|
||||
// // let baz = bar.clone();
|
||||
|
||||
// Ok(())
|
||||
// }
|
||||
}
|
||||
@ -13,7 +13,7 @@ pub fn parse_podcast(chan: &Channel, uri: &str) -> Result<models::NewPodcast> {
|
||||
// Some(foo) => Some(foo.url().to_owned()),
|
||||
// None => None,
|
||||
// };
|
||||
|
||||
// Same as the above match expression.
|
||||
let image_uri = chan.image().map(|foo| foo.url().to_owned());
|
||||
|
||||
let foo = models::NewPodcast {
|
||||
@ -26,6 +26,7 @@ pub fn parse_podcast(chan: &Channel, uri: &str) -> Result<models::NewPodcast> {
|
||||
Ok(foo)
|
||||
}
|
||||
|
||||
// This is also an initial prototype mess.
|
||||
pub fn parse_episode<'a>(item: &'a Item, parent_id: i32) -> Result<models::NewEpisode<'a>> {
|
||||
|
||||
let title = item.title().unwrap();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user