diff --git a/bin/xml2json b/bin/xml2json new file mode 100755 index 0000000..859621a --- /dev/null +++ b/bin/xml2json @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +import argparse +import json +import xmltodict +import sys + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument( + 'infile', + type=argparse.FileType('r'), + nargs='?', + default=sys.stdin, + ) + parser.add_argument( + 'outfile', + type=argparse.FileType('w'), + nargs='?', + default=sys.stdout, + ) + parser.add_argument( + '-p', + '--pretty', + help='Indent JSON with tabs and newlines.', + action='store_true', + default=False, + ) + + args = parser.parse_args() + + args.outfile.write(json.dumps( + xmltodict.parse(args.infile.read()), + indent="\t" if args.pretty else None, + )) + + +if __name__ == '__main__': + main() diff --git a/feedgen.sh b/feedgen.sh index cd7f330..0bf0b18 100755 --- a/feedgen.sh +++ b/feedgen.sh @@ -26,6 +26,35 @@ if ! command -v json2xml >/dev/null 2>&1; then PATH="$DIR/bin:$PATH" fi +function sia_build { + # sia_build lang title description link + log Building $2 feed to $DIR/feeds/sia/$1.xml + mkdir -p $DIR/feeds/sia + curl -s 'https://sia.fi/api/oh-internet-sisallonhallinta/hae_nostolista.srv' \ + -H 'Content-Type: application/json; charset=UTF-8' \ + -d "{ + \"listaus.sivustopolku\": \"/channels/public/www/otkes/$1/index/tutkintaselostukset\", + \"listaus.jsoninput\": \"{\\\"filterfields\\\":\\\"valmistunut_tutkinta\\\", \\\"valmistunut_tutkinta\\\":\\\"true\\\"}\" + }" \ + | grep -v '^\s*$' \ + | xml2json \ + | jq \ + -L $DIR/jq \ + -f $DIR/jq/sia.jq \ + --arg language "$1" \ + --arg title "$2" \ + --arg description "$3" \ + --arg link "$4" \ + | json2xml > $DIR/feeds/sia/$1.xml.new \ + && mv $DIR/feeds/sia/$1.xml.new $DIR/feeds/sia/$1.xml +} + +sia_build en SIA 'Safety Investigation Authority reports' 'https://sia.fi/en/index/currentissues/completedinvestigations.html' +sia_build fi Onnettomuustutkintakeskus 'Onnettomuustutkintakeskus - Valmistuneet tutkinnat' 'https://sia.fi/fi/index/ajankohtaista/valmistuneettutkinnat.html' +sia_build sv Olycksutredningscentralen 'Olycksutredningscentralen - Publicerade rapporter' 'https://sia.fi/sv/index/aktuellt/publiceraderapporter.html' + +exit + log Building ATSB feed to $DIR/feeds/atsb.xml curl -s 'https://www.atsb.gov.au/publications/safety-investigation-reports/?s=1&sort=OccurrenceReleaseDate&sortAscending=descending&investigationStatus=Completed,Discontinued&printAll=true' \ | pup 'table.selectable_grid tr:not(.header) json{}' \ diff --git a/img/rss-finnish.gif b/img/rss-finnish.gif new file mode 100644 index 0000000..69c5b98 Binary files /dev/null and b/img/rss-finnish.gif differ diff --git a/index.html b/index.html index 988ffd6..80a5ea0 100644 --- a/index.html +++ b/index.html @@ -975,6 +975,37 @@ + +

Safety Investigation Authority

+ + + + + + + + + + + + + + + + + + + + + + + +
CountryFinland
LanguageFinnish, Swedish, English
TypeRoad, rail, aviation, marine, industrial, criminal, other
Frequency20 reports/year
Feed + Finnish RSS + Swedish RSS + English RSS +
+ diff --git a/jq/sia.jq b/jq/sia.jq new file mode 100644 index 0000000..6aeb9f8 --- /dev/null +++ b/jq/sia.jq @@ -0,0 +1,38 @@ +# SIA feed generator +# Required arguments: +# $title: Feed title +# $language: ISO 639-1 language code (sv, fi or en) +# $description: Feed description +# $link: Feed link +# Expects xmltodict output holding the API result, outputs xmltodict-compatible JSON +# WARNING: Dates are locale-sensitive; the RSS feed might not generate correctly with another locale. +import "./helpers" as helpers; + +{ + "rss": { + "@version": "2.0", + "channel": { + "title": $title, + "description": $description, + "link": $link, + "language": ($language + "-FI"), + "pubDate": (now | strftime("%a, %d %b %Y %T %z")), + "docs": "https://www.rssboard.org/rss-specification", + "ttl": 1440, + "generator": "ITSB", + "item": [ + .Stato.Card.Card.Card[].Version.Language.Row + | from_entries + | { + "title": .NavigationTitle, + "link": (.public_viewurl | helpers::urlresolve($link)), + "guid": { + "@isPermaLink": "true", + "#text": (.public_viewurl | helpers::urlresolve($link)) + }, + "pubDate": ((.["CMS.Kirjausaika.Epoch"] // .["N_kirjausepoch"]) | tonumber / 1000 | strftime("%a, %d %b %Y %T %z")) + } + ] + } + } +}