Rewrite SKYbrary feed

This commit is contained in:
Lucidiot 2022-01-01 15:58:03 +01:00
parent 4ebb8c7815
commit bbe0f1cca6
Signed by: lucidiot
GPG Key ID: 3358C1CA6906FB8D
2 changed files with 25 additions and 36 deletions

View File

@ -797,18 +797,21 @@
<p>SKYbrary is a project from <a href="https://www.eurocontrol.int/" target="_blank">Eurocontrol</a>
that aims to regroup a lot of aviation safety data, including accident reports.
Although it is not an investigation agency by itself, it is included due to it providing
well-written summaries of accident reports in English as well as
<a href="https://www.skybrary.aero/api.php" target="_blank">an API</a>.</p>
well-written summaries of accident reports in English.</p>
]]>
</description>
<type>Aviation</type>
<frequency>50 reports/year</frequency>
<feed format="rss" lang="English" id="skybrary-rss">
<curl>
<url>https://www.skybrary.aero/api.php?action=askargs&amp;conditions=Category:Accidents_and_Incidents&amp;printouts=Date%20of%20Occurence|GeneralSub|Event%20Type|Aircraft&amp;parameters=|sort%3DDate%20of%20Occurence|order%3Ddesc|limit%3D10000&amp;format=json&amp;api_version=3</url>
<url>https://skybrary.aero/accidents-map</url>
</curl>
<!-- Retrieve the GeoJSON features from within a <script> tag -->
<shell><![CDATA[grep -o '"features":\[.*}\]}\]' | tail -c+12 | head -c-3]]></shell>
<jq path="skybrary.jq" />
<json2xml />
<json2xml>
<namespace prefix="georss">http://www.georss.org/georss</namespace>
</json2xml>
<output>skybrary.xml</output>
</feed>
</source>

View File

@ -1,51 +1,37 @@
#!/usr/bin/jq
# SKYbrary.aero RSS feed generator
# Expects JSON from the "features" property on the Accidents and Incidents map page,
# returns an RSS feed with GeoRSS support.
import "./helpers" as helpers;
{
"rss": {
"@version": "2.0",
"@xmlns": {
"georss": "http://www.georss.org/georss"
},
"channel": {
"title": "SKYbrary Accidents and Incidents",
"description": "Latest accidents and incidents recorded by the SKYbrary project.",
"link": "https://www.skybrary.aero/index.php/Category:Accidents_and_Incidents",
"link": "https://skybrary.aero/accidents-and-incidents",
"language": "en",
"pubDate": (now | strftime("%a, %d %b %Y %T %z")),
"docs": "https://www.rssboard.org/rss-specification",
"ttl": 1440,
"generator": "ITSB",
"item": [
.query.results[]
| values[]
.[]
# Parse the HTML popup content to extract the link and description
| .popup |= capture("^<a href=\"(?<link>[^\"]*)\">.*</a>(?<description>.*)$")
| {
"title": .fulltext,
"link": .fullurl,
"description": (
[
{
"Tags": .printouts["GeneralSub"]|join(", "),
"Aircraft": [.printouts["Aircraft"][].display_title]|join(", "),
"Event Types": [.printouts["Event Type"][].fulltext]|join(", ")
}
| to_entries[]
| "\(.key): \(.value)"
] | join("\n")
),
"pubDate": (
if .printouts["Date of Occurence"]|length then
.printouts["Date of Occurence"][0].timestamp
| tonumber
| strftime("%a, %d %b %Y %T %z")
else [] end
),
"title": .label,
"link": (.popup.link | helpers::urlresolve("https://skybrary.aero/accidents-map")),
"description": .popup.description,
"guid": {
"@isPermaLink": "true",
"#text": .fullurl
"#text": .popup.link
},
"category": [
([.printouts["Event Type"][].fulltext] + .printouts["GeneralSub"])
| unique[]
| {
"@domain": "https://www.skybrary.aero",
"#text": .
}
]
"georss:point": "\(.lat) \(.lon)"
}
]
}