Add more TTSB feeds, close #53

This commit is contained in:
Lucidiot 2021-03-19 18:51:11 +01:00
parent 581253231f
commit 24b2e6cd20
Signed by: lucidiot
GPG Key ID: 3358C1CA6906FB8D
4 changed files with 151 additions and 6 deletions

View File

@ -714,27 +714,76 @@
<url>https://www.ttsb.gov.tw/english/16051/16052/16053/16058/Lpsimplelist?PageSize=1000</url>
</curl>
<pup>#LP-ContentPage .TableList table tbody tr</pup>
<jq path="ttsb.jq">
<arg name="title">TTSB Aviation</arg>
<jq path="ttsb/aviation.jq">
<arg name="lang">en-TW</arg>
<arg name="link">https://www.ttsb.gov.tw/english/16051/16052/16053/16058/Lpsimplelist?PageSize=1000</arg>
</jq>
<json2xml />
<output>ttsb/en/aviation.xml</output>
</feed>
<feed format="rss" lang="English" type="road" id="ttsb-en-road">
<curl>
<url>https://www.ttsb.gov.tw/english/16051/16052/16080/16085/Lpsimplelist?PageSize=1000</url>
</curl>
<pup>#LP-ContentPage .TableList table tbody tr</pup>
<jq path="ttsb/highway-rail.jq">
<arg name="title">TTSB Highway</arg>
<arg name="lang">en-TW</arg>
<arg name="link">https://www.ttsb.gov.tw/english/16051/16052/16080/16085/Lpsimplelist?PageSize=1000</arg>
</jq>
<json2xml />
<output>ttsb/en/highway.xml</output>
</feed>
<feed format="rss" lang="Traditional Chinese" type="aviation" id="ttsb-zh-aviation">
<curl>
<url>https://www.ttsb.gov.tw/1133/1154/1155/1159/Lpsimplelist?PageSize=1000</url>
</curl>
<pup>#LP-ContentPage .TableList table tbody tr</pup>
<jq path="ttsb.jq">
<arg name="title">TTSB Aviation</arg>
<jq path="ttsb/aviation.jq">
<arg name="lang">zh-Hant-TW</arg>
<arg name="link">https://www.ttsb.gov.tw/1133/1154/1155/1159/Lpsimplelist?PageSize=1000</arg>
</jq>
<json2xml />
<output>ttsb/zh/aviation.xml</output>
</feed>
<feed format="rss" lang="Traditional Chinese" type="road" id="ttsb-zh-road">
<curl>
<url>https://www.ttsb.gov.tw/1133/1154/1173/22903/Lpsimplelist?PageSize=1000</url>
</curl>
<pup>#LP-ContentPage .TableList table tbody tr</pup>
<jq path="ttsb/highway-rail.jq">
<arg name="title">TTSB Highway</arg>
<arg name="lang">zh-Hant-TW</arg>
<arg name="link">https://www.ttsb.gov.tw/1133/1154/1173/22903/Lpsimplelist?PageSize=1000</arg>
</jq>
<json2xml />
<output>ttsb/zh/highway.xml</output>
</feed>
<feed format="rss" lang="Traditional Chinese" type="rail" id="ttsb-zh-rail">
<curl>
<url>https://www.ttsb.gov.tw/1133/1154/1163/22877/Lpsimplelist?PageSize=1000</url>
</curl>
<pup>#LP-ContentPage .TableList table tbody tr</pup>
<jq path="ttsb/highway-rail.jq">
<arg name="title">TTSB Railway</arg>
<arg name="lang">zh-Hant-TW</arg>
<arg name="link">https://www.ttsb.gov.tw/1133/1154/1163/22877/Lpsimplelist?PageSize=1000</arg>
</jq>
<json2xml />
<output>ttsb/zh/rail.xml</output>
</feed>
<feed format="rss" lang="Traditional Chinese" type="marine" id="ttsb-zh-marine">
<curl>
<url>https://www.ttsb.gov.tw/1133/1154/1168/22890/Lpsimplelist?PageSize=1000</url>
</curl>
<pup>#LP-ContentPage .TableList table tbody tr</pup>
<jq path="ttsb/marine.jq">
<arg name="lang">zh-Hant-TW</arg>
<arg name="link">https://www.ttsb.gov.tw/1133/1154/1168/22890/Lpsimplelist?PageSize=1000</arg>
</jq>
<json2xml />
<output>ttsb/zh/marine.xml</output>
</feed>
</source>
<source id="skybrary">

48
jq/ttsb/aviation.jq Normal file
View File

@ -0,0 +1,48 @@
# Taiwan Transportation Safety Board Aviation feed generator
# Required arguments:
# $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": "TTSB Aviation",
"description": "TTSB Aviation",
"link": $link,
"language": $lang,
"pubDate": (now | strftime("%a, %d %b %Y %T %z")),
"docs": "https://www.rssboard.org/rss-specification",
"ttl": 1440,
"generator": "ITSB",
"item": [.[] | {
"title": .children[2].children[0].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")
)
}]
}
}
}

View File

@ -20,9 +20,9 @@ import "./helpers" as helpers;
"ttl": 1440,
"generator": "ITSB",
"item": [.[] | {
"title": .children[2].children[0].title,
"title": .children[2].children[0].children[0].title,
"description": [
.children[3:][]
.children[3:(if $lang == "en-TW" then 5 else 7 end)][]
| (
.["data-th"] + ": " + (
.children[0].text

48
jq/ttsb/marine.jq Normal file
View File

@ -0,0 +1,48 @@
# Taiwan Transportation Safety Board Aviation feed generator
# Required arguments:
# $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": "TTSB Marine",
"description": "TTSB Marine",
"link": $link,
"language": $lang,
"pubDate": (now | strftime("%a, %d %b %Y %T %z")),
"docs": "https://www.rssboard.org/rss-specification",
"ttl": 1440,
"generator": "ITSB",
"item": [.[] | {
"title": .children[2].children[0].children[0].title,
"description": [
.children[3:6][]
| (
.["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")
)
}]
}
}
}