TAIID custom feeds, close #44

This commit is contained in:
Lucidiot 2021-02-07 18:37:28 +01:00
parent 3c58102ad8
commit 1228708fad
Signed by: lucidiot
GPG Key ID: 3358C1CA6906FB8D
4 changed files with 127 additions and 9 deletions

View File

@ -26,15 +26,6 @@ if ! command -v json2xml >/dev/null 2>&1; then
PATH="$DIR/bin:$PATH"
fi
log Building ZMA feed to $DIR/feeds/zma.xml
curl -s https://www.zma.go.tz/zma_casuality.php \
| pup '#content2 li a json{}' \
| jq -L $DIR/jq -f $DIR/jq/zma.jq \
| json2xml > $DIR/feeds/zma.xml.new \
&& mv $DIR/feeds/zma.xml.new $DIR/feeds/zma.xml
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{}' \
@ -260,3 +251,36 @@ curl -s https://www.iomshipregistry.com/forms-reports/casualty-reports/ \
| jq -L $DIR/jq -f $DIR/jq/iom.jq \
| json2xml > $DIR/feeds/iom.xml.new \
&& mv $DIR/feeds/iom.xml.new $DIR/feeds/iom.xml
log Building ZMA feed to $DIR/feeds/zma.xml
curl -s https://www.zma.go.tz/zma_casuality.php \
| pup '#content2 li a json{}' \
| jq -L $DIR/jq -f $DIR/jq/zma.jq \
| json2xml > $DIR/feeds/zma.xml.new \
&& mv $DIR/feeds/zma.xml.new $DIR/feeds/zma.xml
function taiid_build {
# taiid_build lang name description url fileName
log Building $2 feed to $DIR/feeds/taiid/$1/$5.xml
mkdir -p $DIR/feeds/taiid/$1
curl -s "$4" \
| pup '.panel-body tr:not(:first-child) json{}' \
| jq \
-L $DIR/jq \
-f $DIR/jq/taiid.jq \
--arg language "$1" \
--arg title "$2" \
--arg description "$3" \
--arg link "$4" \
| json2xml > $DIR/feeds/taiid/$1/$5.xml.new \
&& mv $DIR/feeds/taiid/$1/$5.xml.new $DIR/feeds/taiid/$1/$5.xml
}
taiid_build en TAIID 'Lithuania Transport Accident and Incident Investigations Division reports' 'https://tm.lrv.lt/en/fields-of-activity/transport-accident-and-incident-investigations/accidents-and-incidents' all
taiid_build en 'TAIID Aviation' 'Lithuania Transport Accident and Incident Investigations Division aviation reports' 'https://tm.lrv.lt/en/fields-of-activity/transport-accident-and-incident-investigations/civil-aviation' air
taiid_build en 'TAIID Rail' 'Lithuania Transport Accident and Incident Investigations Division rail reports' 'https://tm.lrv.lt/en/fields-of-activity/transport-accident-and-incident-investigations/railway-transport' rail
taiid_build en 'TAIID Maritime' 'Lithuania Transport Accident and Incident Investigations Division maritime reports' 'https://tm.lrv.lt/en/fields-of-activity/transport-accident-and-incident-investigations/maritime' marine
taiid_build lt TAITS 'Lietuvos Transporto Avarijų ir Incidentų Tyrimai Skyriaus ataskaitos' 'https://tm.lrv.lt/lt/veiklos-sritys-1/transporto-avariju-ir-incidentu-tyrimai-1/avarijos-ir-incidentai' all
taiid_build lt 'TAITS Aviacija' 'Lietuvos Transporto Avarijų ir Incidentų Tyrimai Skyriaus aviacija ataskaitos' 'https://tm.lrv.lt/lt/veiklos-sritys-1/transporto-avariju-ir-incidentu-tyrimai-1/oro-transportas' air
taiid_build lt 'TAITS Geležinkelio' 'Lietuvos Transporto Avarijų ir Incidentų Tyrimai Skyriaus geležinkelio ataskaitos' 'https://tm.lrv.lt/lt/veiklos-sritys-1/transporto-avariju-ir-incidentu-tyrimai-1/gelezinkeliu-transportas' rail
taiid_build lt 'TAITS Jūrinis' 'Lietuvos Transporto Avarijų ir Incidentų Tyrimai Skyriaus jūrinis ataskaitos' 'https://tm.lrv.lt/lt/veiklos-sritys-1/transporto-avariju-ir-incidentu-tyrimai-1/juru-transportas' marine

BIN
img/rss-lietuviu.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 208 B

View File

@ -920,6 +920,61 @@
</tr>
</tbody>
</table>
<h3>Transport Accident and Incident Investigations Division</h3>
<table>
<tr>
<td><strong>Country</strong></td>
<td>Lithuania</td>
</tr>
<tr>
<td><strong>Languages</strong></td>
<td>Lthuanian, English</td>
</tr>
<tr>
<td><strong>Types</strong></td>
<td>Rail, aviation, marine</td>
</tr>
<tr>
<td><strong>Frequency</strong></td>
<td>50-100 reports/year</td>
</tr>
<tr>
<td><strong>Feeds</strong></td>
<td>
<table>
<tr>
<td>All types</td>
<td>
<a href="feeds/taiid/lt/all.xml" target="_blank"><img src="img/rss-lietuviu.gif" alt="Lithuanian RSS" /></a>
<a href="feeds/taiid/en/all.xml" target="_blank"><img src="img/rss-english.gif" alt="English RSS" /></a>
</td>
</tr>
<tr>
<td>Rail</td>
<td>
<a href="feeds/taiid/lt/rail.xml" target="_blank"><img src="img/rss-lietuviu.gif" alt="Lithuanian RSS" /></a>
<a href="feeds/taiid/en/rail.xml" target="_blank"><img src="img/rss-english.gif" alt="English RSS" /></a>
</td>
</tr>
<tr>
<td>Aviation</td>
<td>
<a href="feeds/taiid/lt/air.xml" target="_blank"><img src="img/rss-lietuviu.gif" alt="Lithuanian RSS" /></a>
<a href="feeds/taiid/en/air.xml" target="_blank"><img src="img/rss-english.gif" alt="English RSS" /></a>
</td>
</tr>
<tr>
<td>Marine</td>
<td>
<a href="feeds/taiid/lt/marine.xml" target="_blank"><img src="img/rss-lietuviu.gif" alt="Lithuanian RSS" /></a>
<a href="feeds/taiid/en/marine.xml" target="_blank"><img src="img/rss-english.gif" alt="English RSS" /></a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>
</html>

39
jq/taiid.jq Normal file
View File

@ -0,0 +1,39 @@
# TAIID feed generator
# Required arguments:
# $title: Feed title
# $language: ISO 639-1 language code (lt or en)
# $description: Feed description
# $link: Feed link
# 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.
import "./helpers" as helpers;
{
"rss": {
"@version": "2.0",
"channel": {
"title": $title,
"description": $description,
"link": $link,
"language": ($language + "-LT"),
"pubDate": (now | strftime("%a, %d %b %Y %T %z")),
"docs": "https://www.rssboard.org/rss-specification",
"ttl": 1440,
"generator": "ITSB",
"item": [
.[]
# Ignore reports without links
| select(.children[-2].children != null)
| {
"title": .children[-2].children[0].text,
"link": (.children[-2].children[0].href | helpers::urlresolve($link)),
"guid": {
"@isPermaLink": "true",
"#text": (.children[-2].children[0].href | helpers::urlresolve($link))
},
"pubDate": (.children[-3].text | strptime("%Y-%m-%d") | mktime | strftime("%a, %d %b %Y %T %z"))
}
]
}
}
}