rename
This commit is contained in:
parent
c229cc01ca
commit
9206714c0c
@ -1,6 +1,6 @@
|
|||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
mod law;
|
mod overview;
|
||||||
mod par;
|
mod par;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -38,7 +38,7 @@ impl From<roxmltree::Error> for Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
//law::parse(10001899).unwrap(); //TEG
|
//overview::parse(10001899).unwrap(); //TEG
|
||||||
law::parse(10001848).unwrap(); //UrhG
|
overview::parse(10001848).unwrap(); //UrhG
|
||||||
//par::parse("https://www.ris.bka.gv.at/Dokumente/Bundesnormen/NOR12025172/NOR12025172.xml");
|
//par::parse("https://www.ris.bka.gv.at/Dokumente/Bundesnormen/NOR12025172/NOR12025172.xml");
|
||||||
}
|
}
|
||||||
|
@ -4,25 +4,25 @@ mod parser;
|
|||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use time::{format_description, OffsetDateTime};
|
use time::{format_description, OffsetDateTime};
|
||||||
|
|
||||||
use crate::{law::parser::OgdSearchResult, Error};
|
use crate::{overview::parser::OgdSearchResult, Error};
|
||||||
|
|
||||||
/// Returns the current date in YYYY-MM-DD format. Needed for RIS API query to get current version of the law.
|
/// Returns the current date in YYYY-MM-DD format. Needed for RIS API query to get current version of the overview.
|
||||||
fn current_date() -> String {
|
fn current_date() -> String {
|
||||||
let local_date = OffsetDateTime::now_utc();
|
let local_date = OffsetDateTime::now_utc();
|
||||||
let format = format_description::parse("[year]-[month]-[day]").unwrap(); //unwrap okay, supplied format is fine
|
let format = format_description::parse("[year]-[month]-[day]").unwrap(); //unwrap okay, supplied format is fine
|
||||||
local_date.format(&format).expect("Failed to format date")
|
local_date.format(&format).expect("Failed to format date")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetches the json content of the given law (`law_id`) from the RIS API.
|
/// Fetches the json content of the given overview (`law_id`) from the RIS API.
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
/// Fails if `ureq` can't create a connection, probably because there's no internet connection? (Or RIS is not online.)
|
/// Fails if `ureq` can't create a connection, probably because there's no internet connection? (Or RIS is not online.)
|
||||||
fn fetch_page(law_id: usize) -> Result<String, Error> {
|
fn fetch_page(overview_id: usize) -> Result<String, Error> {
|
||||||
Ok(
|
Ok(
|
||||||
ureq::post("https://data.bka.gv.at/ris/api/v2.6/Bundesrecht")
|
ureq::post("https://data.bka.gv.at/ris/api/v2.6/Bundesrecht")
|
||||||
.send_form(&[
|
.send_form(&[
|
||||||
("Applikation", "BrKons"),
|
("Applikation", "BrKons"),
|
||||||
("Gesetzesnummer", &format!("{}", law_id)),
|
("Gesetzesnummer", &format!("{}", overview_id)),
|
||||||
("DokumenteProSeite", "OneHundred"),
|
("DokumenteProSeite", "OneHundred"),
|
||||||
("Seitennummer", &format!("{}", 1)),
|
("Seitennummer", &format!("{}", 1)),
|
||||||
("Fassung.FassungVom", ¤t_date()),
|
("Fassung.FassungVom", ¤t_date()),
|
||||||
@ -37,8 +37,8 @@ pub(crate) struct Wrapper {
|
|||||||
ogd_search_result: OgdSearchResult,
|
ogd_search_result: OgdSearchResult,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn parse(law_id: usize) -> Result<(), Error> {
|
pub(crate) fn parse(overview_id: usize) -> Result<(), Error> {
|
||||||
let json = fetch_page(law_id)?;
|
let json = fetch_page(overview_id)?;
|
||||||
|
|
||||||
let wrapper: Wrapper = serde_json::from_str(&json)?;
|
let wrapper: Wrapper = serde_json::from_str(&json)?;
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user