SIA custom feeds, close #39
This commit is contained in:
parent
1228708fad
commit
fd44e7000c
|
@ -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()
|
29
feedgen.sh
29
feedgen.sh
|
@ -26,6 +26,35 @@ if ! command -v json2xml >/dev/null 2>&1; then
|
||||||
PATH="$DIR/bin:$PATH"
|
PATH="$DIR/bin:$PATH"
|
||||||
fi
|
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
|
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' \
|
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{}' \
|
| pup 'table.selectable_grid tr:not(.header) json{}' \
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 208 B |
31
index.html
31
index.html
|
@ -975,6 +975,37 @@
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<h3>Safety Investigation Authority</h3>
|
||||||
|
<table>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Country</strong></td>
|
||||||
|
<td>Finland</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Language</strong></td>
|
||||||
|
<td>Finnish, Swedish, English</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Type</strong></td>
|
||||||
|
<td>Road, rail, aviation, marine, industrial, criminal, other</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Frequency</strong></td>
|
||||||
|
<td>20 reports/year</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Feed</strong></td>
|
||||||
|
<td>
|
||||||
|
<a href="feeds/sia/fi.xml" target="_blank"><img src="img/rss-finnish.gif" alt="Finnish RSS" /></a>
|
||||||
|
<a href="feeds/sia/sv.xml" target="_blank"><img src="img/rss-swedish.gif" alt="Swedish RSS" /></a>
|
||||||
|
<a href="feeds/sia/en.xml" target="_blank"><img src="img/rss-english.gif" alt="English RSS" /></a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -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"))
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue