parse full wuchergesetz

This commit is contained in:
2023-11-04 10:53:45 +01:00
parent 9bd90e15bd
commit 816b234112
5 changed files with 54 additions and 4 deletions

View File

@ -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};
@ -13,7 +14,7 @@ fn current_date() -> String {
}
/// Fetches the json content of the given law (`law_id`) from the RIS API.
///
///
/// # Errors
/// 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> {
@ -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(())
}

View File

@ -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)]