Generate TAIC feed

This commit is contained in:
Lucidiot 2019-12-14 11:26:43 +01:00
parent f3f7dc5c2e
commit 262956b874
Signed by: lucidiot
GPG Key ID: 3358C1CA6906FB8D
3 changed files with 60 additions and 1 deletions

View File

@ -11,4 +11,12 @@ echo 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{}' \
| jq -f $DIR/jq/atsb.jq \
| json2xml > $DIR/feeds/atsb.xml.new && mv $DIR/feeds/atsb.xml.new $DIR/feeds/atsb.xml
| json2xml > $DIR/feeds/atsb.xml.new \
&& mv $DIR/feeds/atsb.xml.new $DIR/feeds/atsb.xml
echo Building TAIC feed to $DIR/feeds/taic.xml
curl -s 'https://www.taic.org.nz/inquiries?order=field_publication_date&sort=desc' \
| pup '#view-table-wrapper tbody tr json{}' \
| jq -f $DIR/jq/taic.jq \
| json2xml > $DIR/feeds/taic.xml.new \
&& mv $DIR/feeds/taic.xml.new $DIR/feeds/taic.xml

View File

@ -153,6 +153,32 @@
</tr>
</tbody>
</table>
<h3>Transport Accident Investigation Commission</h3>
<table>
<tbody>
<tr>
<td><strong>Country</strong></td>
<td>New Zealand</td>
</tr>
<tr>
<td><strong>Language</strong></td>
<td>English</td>
</tr>
<tr>
<td><strong>Types</strong></td>
<td>Rail, aviation, marine</td>
</tr>
<tr>
<td><strong>Frequency</strong></td>
<td>10-20 reports/year</td>
</tr>
<tr>
<td><strong>Feed</strong></td>
<td><a href="feeds/taic.xml" target="_blank">link</a></td>
</tr>
</tbody>
</table>
</div>
</body>
</html>

25
jq/taic.jq Normal file
View File

@ -0,0 +1,25 @@
# TAIC feed generator from https://www.taic.org.nz/inquiries?order=field_publication_date&sort=desc
# Expects pup JSON output holding <tr> tags, outputs xmltodict-compatible JSON
# WARNING: Dates are locale-sensitive; the RSS feed might not generate correctly with another locale.
{
"rss": {
"@version": "2.0",
"channel": {
"title": "TAIC",
"description": "Transport Accident Investigation Commission accident reports",
"link": "https://www.taic.org.nz/inquiries",
"language": "en-nz",
"pubDate": (now | strftime("%a, %d %b %Y %T %z")),
"docs": "https://cyber.harvard.edu/rss/rss.html",
"ttl": 86400,
"generator": "ITSB",
"item": [.[] | {
"title": .children[0].children[1].text,
"description": .children[0].children[2].text,
"link": ("https://www.taic.org.nz" + .children[0].children[1].href),
"pubDate": (.children[3].children[0].datetime | fromdateiso8601 | strftime("%a, %d %b %Y %T %z"))
}]
}
}
}