@@ -40,13 +40,17 @@ function parseFinlexUrl(url: string): { docYear: number; docNumber: string; docL
4040 }
4141}
4242
43- function buildFinlexUrl ( statute : StatuteKey ) : string {
44- // const baseUrl = 'https://opendata.finlex.fi/finlex/avoindata/v1/akn/fi/act/statute-consolidated';
45- // return `${baseUrl}/${statute.year}/${statute.number}/${statute.language}@${statute.version ? statute.version : ''}`;
43+ function buildFinlexUrl ( statute : StatuteKey ) : { uri : string , uriOld : string } {
44+ const oldBaseUrl = 'https://opendata.finlex.fi/finlex/avoindata/v1/akn/fi/act/statute-consolidated' ;
4645 const baseUrl = 'https://opendata.finlex.fi/finlex/avoindata/v1/akn/fi/act/statute'
47- return `${ baseUrl } /${ statute . year } /${ statute . number } /${ statute . language } @` ;
46+ return {
47+ uri : `${ baseUrl } /${ statute . year } /${ statute . number } /${ statute . language } @` ,
48+ uriOld : `${ oldBaseUrl } /${ statute . year } /${ statute . number } /${ statute . language } @${ statute . version ? statute . version : '' } `
49+ } ;
4850}
4951
52+
53+
5054function parseJudgmentUrl ( url : string ) : JudgmentKey {
5155 const u = new URL ( url )
5256 const parts = u . pathname . split ( "/" ) . filter ( p => p !== "" )
@@ -323,10 +327,29 @@ async function setImages(statuteUuid: string, docYear: number, docNumber: string
323327 }
324328}
325329
326- async function setSingleStatute ( uri : string ) {
327- const result = await axios . get ( `${ uri } ` , {
328- headers : { 'Accept' : 'application/xml' , 'Accept-Encoding' : 'gzip' }
329- } )
330+ async function fetchStatute ( uri : string ) {
331+ try {
332+ const result = await axios . get ( `${ uri } ` , {
333+ headers : { 'Accept' : 'application/xml' , 'Accept-Encoding' : 'gzip' }
334+ } )
335+ return result
336+ } catch {
337+ return null
338+ }
339+ }
340+
341+ async function setSingleStatute ( uris : { uri : string , uriOld : string } ) {
342+ const { uri, uriOld } = uris
343+ let result = await fetchStatute ( uri )
344+ if ( ! result ) {
345+ result = await fetchStatute ( uriOld )
346+ if ( ! result ) {
347+ console . log ( ' --> not found: ' , uri )
348+ console . log ( ' --> : ' , uriOld )
349+ return null
350+ }
351+ }
352+
330353 const docTitle = await parseTitlefromXML ( result )
331354 const imageLinks = await parseImagesfromXML ( result )
332355 const keywordList = await parseKeywordsfromXML ( result )
0 commit comments