itsb/jq/ttsb.jq

50 lines
1.9 KiB
Plaintext

# Taiwan Transportation Safety Board Aviation feed generator
# Required arguments:
# $title: Feed title
# $lang: Feed language
# $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": $title,
"link": $link,
"language": $lang,
"pubDate": (now | strftime("%a, %d %b %Y %T %z")),
"docs": "https://cyber.harvard.edu/rss/rss.html",
"ttl": 86400,
"generator": "ITSB",
"item": [.[] | {
"title": .children[2].children[0].title,
"description": [
.children[3:][]
| (
.["data-th"] + ": " + (
.children[0].text
// .children[0].children[0].text
// "—"
)
)
] | join("\n"),
"link": (.children[2].children[0].children[0].href | helpers::urlresolve($link)),
"pubDate": (
.children[1].children[0].text
| strptime("%Y-%m-%d")
# strptime returns a [year, month, day, …] array
# To handle the Chinese calendar, which is sometimes used by the TTSB feeds,
# we add 1911 years to the parsed date when it is below 1998,
# 1999 being the year of their earliest investigation.
| .[0] |= if . <= 1998 then (. + 1911) else . end
| mktime
| strftime("%a, %d %b %Y %T %z")
)
}]
}
}
}