Fetch release date

This commit is contained in:
dolphinau 2025-07-02 16:25:57 +02:00
parent df96c91b4b
commit 4a20c539f6
No known key found for this signature in database
3 changed files with 51 additions and 2 deletions

View file

@ -4,3 +4,11 @@ version = "0.1.0"
edition = "2024"
[dependencies]
tokio = { version = "1.46.0", default-features = false, features = [
"rt-multi-thread",
] }
futures = "0.3.31"
reqwest = "0.12.22"
scraper = "0.23.1"
regex = "1.11.1"
chrono = "0.4.41"

View file

@ -22,11 +22,14 @@
packages = {
default = self.packages.${system}.myapp;
};
# $ nix develop
devShells.default = pkgs.mkShell {
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [pkgs.openssl];
packages = [
pkgs.gnumake
pkgs.pkg-config
pkgs.openssl
# Nix
pkgs.nixpkgs-fmt

View file

@ -1,3 +1,41 @@
use chrono::NaiveDate;
use regex::Regex;
use reqwest::get;
use scraper::{Html, Selector};
use tokio::runtime::Runtime;
fn main() {
println!("Hello, world!");
let rt = Runtime::new().unwrap();
rt.block_on(fetch_release_date("https://lwn.net/Articles/1025629/"));
}
async fn fetch_release_date(url: &str) -> Option<NaiveDate> {
let response = get(url).await.unwrap();
let response_text = response.text().await.unwrap();
if let Some(article_text) = Html::parse_document(&response_text)
.select(&Selector::parse("div.ArticleText").unwrap())
.next()
{
if let Some(yes) = article_text.select(&Selector::parse("p").unwrap()).last() {
let re = Regex::new(
r#"(?m)\(Alternatively, this item will become freely\n\s* available on ([A-Z][a-z]+ [0-9]{2}, [0-9]{4})\)"#,
)
.unwrap();
if let Some(cap) = re.captures(&yes.inner_html()) {
if let Some(date) = cap.get(1) {
return NaiveDate::parse_from_str(date.as_str(), "%B %d, %Y").ok();
}
}
}
}
None
}
async fn fetch_paid_articles() -> Option<Vec<String>> {
let response = get("https://lwn.net/headlines/rss").await.unwrap();
let response_text = response.text().await.unwrap();
None
}