From b08f260fa9df9266a78f4ba178ed1a17f7d5cfc5 Mon Sep 17 00:00:00 2001 From: Lucidiot Date: Sat, 25 Jul 2020 23:06:58 +0200 Subject: [PATCH] Add TTSB feeds, close #8 --- feedgen.sh | 22 ++++++++++++++++++++ img/rss-chinese.gif | Bin 0 -> 208 bytes index.html | 36 ++++++++++++++++++++++++++++++++ jq/ttsb.jq | 49 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 img/rss-chinese.gif create mode 100644 jq/ttsb.jq diff --git a/feedgen.sh b/feedgen.sh index dc80e9f..ed15fe8 100755 --- a/feedgen.sh +++ b/feedgen.sh @@ -78,6 +78,28 @@ curl -s 'https://en.havarikommissionen.dk/railway-archive/' \ | json2xml -s -ns 'http://search.yahoo.com/mrss/' media > $DIR/feeds/aibd/rail.xml.new \ && mv $DIR/feeds/aibd/rail.xml.new $DIR/feeds/aibd/rail.xml +log Building TTSB Aviation English feed to $DIR/feeds/ttsb/en/aviation.xml +mkdir -p $DIR/feeds/ttsb/en +curl -s 'https://www.ttsb.gov.tw/english/16051/16052/16053/16058/Lpsimplelist?PageSize=1000' \ + | pup '#LP-ContentPage .TableList table tbody tr json{}' \ + | jq -L $DIR/jq -f $DIR/jq/ttsb.jq \ + --arg title 'TTSB Aviation' \ + --arg lang 'en-TW' \ + --arg link 'https://www.ttsb.gov.tw/english/16051/16052/16053/16058/Lpsimplelist?PageSize=1000' \ + | json2xml > $DIR/feeds/ttsb/en/aviation.xml.new \ + && mv $DIR/feeds/ttsb/en/aviation.xml.new $DIR/feeds/ttsb/en/aviation.xml + +log Building TTSB Aviation Chinese feed to $DIR/feeds/ttsb/zh/aviation.xml +mkdir -p $DIR/feeds/ttsb/zh +curl -s 'https://www.ttsb.gov.tw/1133/1154/1155/1159/Lpsimplelist?PageSize=1000' \ + | pup '#LP-ContentPage .TableList table tbody tr json{}' \ + | jq -L $DIR/jq -f $DIR/jq/ttsb.jq \ + --arg title '國家運輸安全調查委員會' \ + --arg lang 'zh-Hant-TW' \ + --arg link 'https://www.ttsb.gov.tw/1133/1154/1155/1159/Lpsimplelist?PageSize=1000' \ + | json2xml > $DIR/feeds/ttsb/zh/aviation.xml.new \ + && mv $DIR/feeds/ttsb/zh/aviation.xml.new $DIR/feeds/ttsb/zh/aviation.xml + log Building BFU English feed to $DIR/feeds/bfu/en.xml mkdir -p $DIR/feeds/bfu curl -s 'https://www.bfu-web.de/EN/Publications/Investigation%20Report/reports_node.html?cms_gts=238148_list%253DdateOfIssue_dt%252Bdesc' \ diff --git a/img/rss-chinese.gif b/img/rss-chinese.gif new file mode 100644 index 0000000000000000000000000000000000000000..11d8c4ff829d6ab51efd134c8d50e5c6b239b706 GIT binary patch literal 208 zcmV;>05AVXNk%w1VNd`M0PzC=W@cvpW&ntYfdBvhA^8LV00000EC2ui08juA0007^ zgpaAq?GMkGwAzca-n^R;gyKk+!62mS%C_zczr$zNCK~7Z-p&AM3x;sKqOnICPDT__ zbI6*gaMTo$Dz#=QJ0I{g3^PkaLDg(co6qGkn&)*c<;?GC<*ukveC_q`CX)naC+6gY zx2O2F<#N_F2qZaoLV1UGwV1hv1qk^gBouf=suLG#Gg`XpIEYHd8XM!)QEPjPixIKQ K+v}@P002ASwqCCQ literal 0 HcmV?d00001 diff --git a/index.html b/index.html index fc8b7c5..9dbe788 100644 --- a/index.html +++ b/index.html @@ -658,6 +658,42 @@ + +

Taiwan Transportation Safety Board

+ + + + + + + + + + + + + + + + + + + + + + + +
CountryTaiwan
LanguageTraditional Chinese, English
TypesAviation, rail, marine, highway
Frequency10 reports/year
Feeds + + + + + +
Aviation + Chinese RSS + English RSS +
+
diff --git a/jq/ttsb.jq b/jq/ttsb.jq new file mode 100644 index 0000000..75a84b1 --- /dev/null +++ b/jq/ttsb.jq @@ -0,0 +1,49 @@ +# Taiwan Transportation Safety Board Aviation feed generator +# Required arguments: +# $title: Feed title +# $lang: Feed language +# $link: Feed link +# Expects pup JSON output holding 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") + ) + }] + } + } +}