risp/src/law/mod.rs

57 lines
1.4 KiB
Rust
Raw Normal View History

2023-11-03 22:40:19 +01:00
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<String, Error> {
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", &current_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<Data>,
}
#[derive(Deserialize)]
struct Data {}
pub(crate) fn parse(law_id: usize) -> Result<(), Error> {
let result = fetch_page(law_id)?;
println!("{result:#?}");
Ok(())
}