parse full wuchergesetz
This commit is contained in:
parent
9bd90e15bd
commit
816b234112
@ -1,6 +1,7 @@
|
||||
/// This module contains everything everything, to convert the given JSON file into Rust structs using serde.
|
||||
mod parser;
|
||||
|
||||
use serde::Deserialize;
|
||||
use time::{format_description, OffsetDateTime};
|
||||
|
||||
use crate::{law::parser::OgdSearchResult, Error};
|
||||
@ -30,10 +31,20 @@ fn fetch_page(law_id: usize) -> Result<String, Error> {
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
pub(crate) struct Wrapper {
|
||||
ogd_search_result: OgdSearchResult,
|
||||
}
|
||||
|
||||
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)?;
|
||||
let wrapper: Wrapper = serde_json::from_str(&json)?;
|
||||
|
||||
for par in wrapper.ogd_search_result.get_par() {
|
||||
crate::par::parse(&par).unwrap();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -20,6 +20,24 @@ impl OgdSearchResult {
|
||||
fn has_next_page(&self) -> bool {
|
||||
todo!();
|
||||
}
|
||||
|
||||
pub(crate) fn get_par(&self) -> Vec<String> {
|
||||
let mut ret = Vec::new();
|
||||
for doc_ref in &self.ogd_document_results.ogd_document_reference {
|
||||
for urls in &doc_ref
|
||||
.data
|
||||
.document_list
|
||||
.content_reference
|
||||
.urls
|
||||
.content_url
|
||||
{
|
||||
if urls.data_type == "Xml" {
|
||||
ret.push(urls.url.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
@ -38,6 +38,6 @@ impl From<roxmltree::Error> for Error {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
//law::parse(10001905);
|
||||
par::parse("https://www.ris.bka.gv.at/Dokumente/Bundesnormen/NOR12025172/NOR12025172.xml");
|
||||
law::parse(10001899).unwrap();
|
||||
//par::parse("https://www.ris.bka.gv.at/Dokumente/Bundesnormen/NOR12025172/NOR12025172.xml");
|
||||
}
|
||||
|
@ -10,5 +10,7 @@ pub(crate) fn parse(url: &str) -> Result<(), Error> {
|
||||
let xml = fetch_page(url)?;
|
||||
let risdok = Risdok::from_str(&xml)?;
|
||||
|
||||
println!("{risdok}");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
use roxmltree::Node;
|
||||
|
||||
use crate::Error;
|
||||
@ -34,6 +36,23 @@ impl Risdok {
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Risdok {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
if let Some(par_header) = &self.nutzdaten.abschnitt.ueberschriftPara {
|
||||
f.write_str(&format!("# {}", par_header.content))?;
|
||||
}
|
||||
for abs in &self.nutzdaten.abschnitt.absatze {
|
||||
let mut w = String::new();
|
||||
if let Some(symb) = &abs.gldsym {
|
||||
w.push_str(&format!("\n{symb} "));
|
||||
}
|
||||
w.push_str(&format!("{}\n", abs.content));
|
||||
f.write_str(&w)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub(crate) struct Metadaten;
|
||||
impl Metadaten {
|
||||
|
Loading…
Reference in New Issue
Block a user