Created
December 14, 2024 14:05
-
-
Save sheepla/7819a81a008c0a5b5df5232b2c06e805 to your computer and use it in GitHub Desktop.
Fetch AUR page and extract PKGBILD and other filees diff info in Rust (reqwest + select-rs)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use eyre::OptionExt; | |
use reqwest::Url; | |
use select::{ | |
document::Document, | |
predicate::{Class, Name, Predicate}, | |
}; | |
use serde::{Deserialize, Serialize}; | |
#[derive(Debug, Serialize, Deserialize, Default)] | |
pub struct DiffInfo { | |
pub summary: String, | |
pub content: String, | |
} | |
pub async fn fetch_pkgbuild_diffinfo(package_name: &str) -> eyre::Result<DiffInfo> { | |
let mut url = Url::parse("https://aur.archlinux.org/cgit/aur.git/diff/")?; | |
{ | |
url.query_pairs_mut().append_pair("h", package_name); | |
} | |
let response = reqwest::get(url).await?; | |
let text = response.text().await?; | |
let document = Document::from(text.as_str()); | |
Ok(DiffInfo { | |
summary: document | |
.find(Class("diffstat-summary")) | |
.next() | |
.map(|node| node.text()) | |
.ok_or_eyre("summary node text was not found")?, | |
content: document | |
.find( | |
Class("diff").descendant(Name("tr").descendant(Name("td")).descendant(Name("div"))), | |
) | |
.map(|node| node.text()) | |
.collect::<Vec<_>>() | |
.join("\n"), | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hmm, I want to parse by bytes stream from
reqwest::Response
.