mirror of
https://gitlab.com/news-flash/article_scraper.git
synced 2025-07-08 16:40:00 +02:00
load config files in background thread
This commit is contained in:
parent
2cac8a2678
commit
f570873aba
8 changed files with 480 additions and 326 deletions
|
@ -1,13 +1,10 @@
|
|||
use std;
|
||||
use url::Url;
|
||||
use std::path::PathBuf;
|
||||
use crate::error::{ScraperError, ScraperErrorKind};
|
||||
use chrono::NaiveDateTime;
|
||||
use crate::error::{
|
||||
ScraperError,
|
||||
ScraperErrorKind,
|
||||
};
|
||||
use std::io::Write;
|
||||
use failure::ResultExt;
|
||||
use std;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
use url::Url;
|
||||
|
||||
pub struct Article {
|
||||
pub title: Option<String>,
|
||||
|
@ -19,7 +16,6 @@ pub struct Article {
|
|||
|
||||
impl Article {
|
||||
pub fn save_html(&self, path: &PathBuf) -> Result<(), ScraperError> {
|
||||
|
||||
if let Some(ref html) = self.html {
|
||||
if let Ok(()) = std::fs::create_dir_all(&path) {
|
||||
let mut file_name = match self.title.clone() {
|
||||
|
@ -29,12 +25,13 @@ impl Article {
|
|||
file_name.push_str(".html");
|
||||
let path = path.join(file_name);
|
||||
let mut html_file = std::fs::File::create(&path).context(ScraperErrorKind::IO)?;
|
||||
html_file.write_all(html.as_bytes()).context(ScraperErrorKind::IO)?;
|
||||
return Ok(())
|
||||
html_file
|
||||
.write_all(html.as_bytes())
|
||||
.context(ScraperErrorKind::IO)?;
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
Err(ScraperErrorKind::Unknown)?
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue