risp/src/law/mod.rs
2023-11-04 00:19:12 +01:00

35 lines
1.1 KiB
Rust

/// This module contains everything everything, to convert the given JSON file into Rust structs using serde.
mod parser;
use time::{format_description, OffsetDateTime};
use crate::{law::parser::OgdSearchResult, Error};
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()?,
)
}
pub(crate) fn parse(law_id: usize) -> Result<(), Error> {
let json = fetch_page(law_id)?;
let ogd_search_result: OgdSearchResult = serde_json::from_str(&json)?;
Ok(())
}