itsb/jq/daai.jq

58 lines
2.5 KiB
Plaintext

# DAAI feed generator
# Expects pup JSON output holding <table> 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": "DAAI",
"description": "Namibian Directorate of Aircraft Accidents and Investigation reports",
"link": "https://mwt.gov.na/web/mwt/published-reports",
"language": "en-na",
"pubDate": (now | strftime("%a, %d %b %Y %T %z")),
"docs": "https://www.rssboard.org/rss-specification",
"ttl": 1440,
"generator": "ITSB",
"item": [
# Ignore table headers
.[].children[].children[2:][]
# Ignore empty lines
| select(.children[3].children)
| {
"title": (
# Accident/Incident
(.children[1] | [..|.text?|strings][0])
+ " - "
# Aircraft type
+ (.children[2] | [..|.text?|strings][0])
+ " "
# Aircraft registration
+ (.children[3] | [..|.text?|strings][0])
+ " - "
# Report type (final/preliminary)
+ (.children[4] | [..|.text?|strings][0])
),
"link": (.children[3].children[0].href | helpers::urlresolve("https://mwt.gov.na/web/mwt/published-reports")),
"pubDate": ((.children[0] | [..|.text?|strings][0]) | gsub("\\s+"; " ") | strptime("%d %B %Y") | mktime | strftime("%a, %d %b %Y %T %z")),
"guid": {
"@isPermaLink": "true",
"#text": (.children[3].children[0].href | helpers::urlresolve("https://mwt.gov.na/web/mwt/published-reports"))
},
"category": [
{
"@domain": "https://mwt.gov.na",
"#text": (.children[1] | [..|.text?|strings][0])
},
{
"@domain": "https://mwt.gov.na",
"#text": (.children[4] | [..|.text?|strings][0])
}
]
}
]
}
}
}