parse full wuchergesetz
This commit is contained in:
@ -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(())
|
||||
}
|
||||
|
@ -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)]
|
||||
|
Reference in New Issue
Block a user