Skip to content

Commit

Permalink
reasonable console output
Browse files Browse the repository at this point in the history
  • Loading branch information
Eberhard Kahlenberger committed Jun 1, 2024
1 parent edc1c49 commit 88c8595
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
[package]
name = "readpage"
version = "0.1.0"
version = "0.2.0"
edition = "2021"

[dependencies]
article_scraper = "^2"
clap = { version = "^4.5", features = ["cargo", "color"] }
html-escape = "0.2.13"
html2text = "0.12.5"
reqwest = {version = "^0.12", features = ["blocking", "charset"] }
termsize = "0.1.6"
thiserror = "1.0.61"
url = "2.5.0"
tokio = "1.38.0"
url = "2.5.0"

27 changes: 22 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ mod Error;

use article_scraper::ArticleScraper;
use clap::{arg, command};
use html2text::from_read;
use html_escape::decode_html_entities;
use reqwest::Client;
use termsize::Size;
use tokio;
use url::Url;


use Error::AppError;

#[tokio::main]
async fn main() -> Result<(), AppError> {
async fn main() -> Result<(), AppError>
{
let matches = command!()
.arg(arg!([url] "The URL to a website to read out").required(true))
.get_matches();
Expand All @@ -22,8 +26,21 @@ async fn main() -> Result<(), AppError> {
let parsedUrl = Url::parse(url).map_err(|e| AppError::UrlParseError(e))?;
let client = Client::new();
let article = scraper.parse(&parsedUrl,false,&client,None).await.map_err(|e| AppError::ScrapeError(e.to_string()))?;
println!("{}",article.html.unwrap());
if let Some(html) = article.html
{
println!("{}\n", url);
println!("{}", article.title.unwrap_or_else(|| "No Title".to_string()));

let readable_text = from_read(
decode_html_entities(&html).as_bytes(),
termsize::get().
unwrap_or(Size { cols: 100, rows: 0 }).
cols as usize);
println!("{}", readable_text);
}
else
{
println!("There is nothing readable at: {}", url);
}
Ok(())
}


}

0 comments on commit 88c8595

Please sign in to comment.