Custom feeds for Denmark's AIBD and DMAIB

This commit is contained in:
Lucidiot 2019-12-14 17:42:43 +01:00
parent fd5e71199d
commit d8d47b6cbb
Signed by: lucidiot
GPG Key ID: 3358C1CA6906FB8D
4 changed files with 123 additions and 1 deletions

View File

@ -65,3 +65,34 @@ curl -s 'https://jtsb.mlit.go.jp/jtsb/ship/ship-kensaku-list.php?sort=desc&by=p'
| jq -f $DIR/jq/jtsb/jp/marine.jq \
| json2xml > $DIR/feeds/jtsb/jp/marine.xml.new \
&& mv $DIR/feeds/jtsb/jp/marine.xml.new $DIR/feeds/jtsb/jp/marine.xml
echo Building AIBD Aviation feed to $DIR/feeds/aibd/aviation.xml
mkdir -p $DIR/feeds/aibd
curl -s 'https://en.havarikommissionen.dk/aviation-archive/' \
| pup 'ul.items > li[data-url] json{}' \
| jq -f $DIR/jq/denmark.jq \
--arg title 'AIBD Aviation' \
--arg description 'Accident Investigation Board Denmark aviation accident reports' \
--arg link 'https://en.havarikommissionen.dk/aviation-archive/' \
| json2xml > $DIR/feeds/aibd/aviation.xml.new \
&& mv $DIR/feeds/aibd/aviation.xml.new $DIR/feeds/aibd/aviation.xml
echo Building AIBD Rail feed to $DIR/feeds/aibd/rail.xml
curl -s 'https://en.havarikommissionen.dk/railway-archive/' \
| pup 'ul.items > li[data-url] json{}' \
| jq -f $DIR/jq/denmark.jq \
--arg title 'AIBD Rail' \
--arg description 'Accident Investigation Board Denmark railroad accident reports' \
--arg link 'https://en.havarikommissionen.dk/railway-archive/' \
| json2xml > $DIR/feeds/aibd/rail.xml.new \
&& mv $DIR/feeds/aibd/rail.xml.new $DIR/feeds/aibd/rail.xml
echo Building DMAIB feed to $DIR/feeds/dmaib.xml
curl -s 'https://dmaib.com/reports/?categorizations=9510' \
| pup 'ul.items > li[data-url] json{}' \
| jq -f $DIR/jq/denmark.jq \
--arg title 'DMAIB' \
--arg description 'Danish Maritime Accident Investigation Board accident reports' \
--arg link 'https://dmaib.com/reports/?categorizations=9510' \
| json2xml > $DIR/feeds/dmaib.xml.new \
&& mv $DIR/feeds/dmaib.xml.new $DIR/feeds/dmaib.xml

View File

@ -266,6 +266,58 @@
</tr>
</tbody>
</table>
<h3>Accident Investigation Board Denmark</h3>
<table>
<tbody>
<tr>
<td><strong>Country</strong></td>
<td>Denmark</td>
</tr>
<tr>
<td><strong>Language</strong></td>
<td>Danish, English</td>
</tr>
<tr>
<td><strong>Types</strong></td>
<td>Rail, aviation</td>
</tr>
<tr>
<td><strong>Frequency</strong></td>
<td>10-20 reports/year</td>
</tr>
<tr>
<td><strong>Feeds</strong></td>
<td><a href="feeds/aibd/aviation.xml" target="_blank">Aviation</a> &mdash; <a href="feeds/aibd/rail.xml" target="_blank">Rail</a></td>
</tr>
</tbody>
</table>
<h3>Danish Maritime Accident Investigation Board</h3>
<table>
<tbody>
<tr>
<td><strong>Country</strong></td>
<td>Denmark</td>
</tr>
<tr>
<td><strong>Language</strong></td>
<td>Danish, English</td>
</tr>
<tr>
<td><strong>Types</strong></td>
<td>Marine</td>
</tr>
<tr>
<td><strong>Frequency</strong></td>
<td>1-5 reports/year</td>
</tr>
<tr>
<td><strong>Feed</strong></td>
<td><a href="feeds/dmaib.xml" target="_blank">rss</a></td>
</tr>
</tbody>
</table>
</div>
</body>
</html>

39
jq/denmark.jq Normal file
View File

@ -0,0 +1,39 @@
# Denmark feed generator
# Compatible with AIBD Aviation https://en.havarikommissionen.dk/aviation-archive/
# Compatible with AIBD Rail https://en.havarikommissionen.dk/railway-archive/
# Compatible with DMAIB https://dmaib.com/reports/?categorizations=9510
# Required arguments:
# $title: Channel title
# $description: Channel description
# $link: Channel link
# Expects pup JSON output holding <li> tags, outputs xmltodict-compatible JSON
# WARNING: Dates are locale-sensitive; the RSS feed might not generate correctly with another locale.
{
"rss": {
"@version": "2.0",
"@xmlns:media": "http://search.yahoo.com/mrss/",
"channel": {
"title": $title,
"description": $description,
"link": $link,
"language": "en",
"pubDate": (now | strftime("%a, %d %b %Y %T %z")),
"docs": "https://cyber.harvard.edu/rss/rss.html",
"ttl": 86400,
"generator": "ITSB",
"item": [.[] | {
"title": first(.children[-1].children[] | select(.tag == "h3")).children[0].text,
"description": first(.children[-1].children[] | select(.tag == "p")).text,
"link": .["data-url"],
"pubDate": (first(.children[-1].children[] | select(.class == "date")).text[-10:] | strptime("%d-%m-%Y") | mktime | strftime("%a, %d %b %Y %T %z")),
"category": [.children[-1].children[] | select(.class == "labels") | .children[].text],
"media:thumbnail": (
if .children[0].class == "media-left" then {
"@url": .children[0].children[0].src
} else empty end
)
}]
}
}
}

View File

@ -13,7 +13,7 @@
"pubDate": (now | strftime("%a, %d %b %Y %T %z")),
"docs": "https://cyber.harvard.edu/rss/rss.html",
"ttl": 86400,
"generator": "ITSB",
"generator": "ITSB",
"item": [.[] | {
"title": .children[0].children[1].text,
"description": .children[0].children[2].text,