mod hits; use serde::Deserialize; use time::{format_description, OffsetDateTime}; use crate::Error; use self::hits::Hits; fn current_date() -> String { let local_date = OffsetDateTime::now_utc(); let format = format_description::parse("[year]-[month]-[day]").unwrap(); //OK local_date.format(&format).expect("Failed to format date") } fn fetch_page(law_id: usize) -> Result { Ok( ureq::post("https://data.bka.gv.at/ris/api/v2.6/Bundesrecht") .send_form(&[ ("Applikation", "BrKons"), ("Gesetzesnummer", &format!("{}", law_id)), ("DokumenteProSeite", "OneHundred"), ("Seitennummer", &format!("{}", 1)), ("Fassung.FassungVom", ¤t_date()), ])? .into_string()?, ) } #[derive(Deserialize)] struct OgdSearchResult { #[serde(rename = "OgdSearchResult")] ogd_document_results: OgdDocumentResults, } #[derive(Deserialize)] struct OgdDocumentResults { hits: Hits, #[serde(rename = "OgdDocumentReference")] ogd_document_reference: OgdDocumentReference, } #[derive(Deserialize)] struct OgdDocumentReference { #[serde(rename = "Data")] data: Vec, } #[derive(Deserialize)] struct Data {} pub(crate) fn parse(law_id: usize) -> Result<(), Error> { let result = fetch_page(law_id)?; println!("{result:#?}"); Ok(()) }