risp/src/law/mod.rs

34 lines
1003 B
Rust
Raw Normal View History

2023-11-04 00:05:38 +01:00
mod parser;
2023-11-03 22:40:19 +01:00
use time::{format_description, OffsetDateTime};
2023-11-04 00:05:38 +01:00
use crate::{law::parser::OgdSearchResult, Error};
2023-11-03 22:40:19 +01:00
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()?,
)
}
2023-11-04 00:05:38 +01:00
pub(crate) fn parse(law_id: usize) -> Result<(), Error> {
let json = fetch_page(law_id)?;
2023-11-03 22:40:19 +01:00
2023-11-04 00:05:38 +01:00
let ogd_search_result: OgdSearchResult = serde_json::from_str(&json)?;
2023-11-03 22:40:19 +01:00
Ok(())
}