0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

日本の道路開通予定を Wikipedia 記事から調べる(シェルスクリプト)

0
Last updated at Posted at 2026-03-05

こんにちは。
日本の道路開通予定を Wikipedia 記事から調べました(シェルスクリプト)。

動作例

$ ./road_open_planned.sh
2026年
3月
7日
 都市計画道路宮﨑駅東通線 3工区 宮崎県宮崎市吉村町西中甲 - 吉村町前田甲 (0.502 km)
8日
 徳島南部自動車道 阿南IC - 小松島南IC (3.2 km)
 :
 :

source code

road_open_planned.sh
#!/bin/bash

# constants
url_wiki="https://ja.wikipedia.org/wiki/"
url_planned="${url_wiki}Portal:""$(echo "道路/予定事項" | jq -Rr @uri)"
tmpdir=$(mktemp -d "${TMPDIR:-/tmp/}$(basename "$0")".XXXXXXXXX)

# check
commands_required="html2text jq"
for c in $commands_required; do
  command -v "$c" 1>/dev/null || { echo "please install $c." 1>&2; exit 1; }
done

# functions
block_f() {
  while IFS= read -r line; do
    if [[ $line =~ [年月]$ ]]; then
      echo "$line"
      buffer=""  # clear
    elif [[ $line =~ ^[[:space:]] ]]; then
      if [[ -n $buffer ]]; then
        echo "$buffer"
      fi
      echo "$line"
      buffer=""  # clear
    else 
      buffer="$line"  # update
    fi
  done
}

grep__f() {
  grep -e "o (開通)" -e "\* 春$" -e "\* 夏$" -e "\* 秋$" -e "\* 冬$" -e "\* 年内$" -e "\* 年度内$" -e "\* .*本年.*$" -e "\* [0-9][0-9]*日$" -e "^[0-9][0-9]*月$" -e "^[0-9]*年$"
}

grep_f() {
  grep__f | grep -v -e "(拡幅)" -e "(IC供用)" -e "(無料開放)" -e "(フルIC化)" -e "(PA供用)" -e "なお日時が" -e "利用制限撤廃" -e "ICランプ供用" | sed -e 's/\[日本の旗\]//g' | sed -e 's/\[編集\]//g' | sed -e 's/^ *//g' | sed -e '/^--/d' | sed -e 's/o (開通)//g' | sed -e 's/^* //' | sed -e 's/\[.*\]//g' | block_f
}

curl_f() {
  url="$1"
  curl -s "$url" > "$tmpdir"/pages.html
  html2text -nobs "$tmpdir"/pages.html
}

# main
year=$(date +%Y)
z=$(echo "年の道路" | jq -Rr @uri)
for y in $year $(( year + 1 )); do
  printf "%s\n" "$y""年"
  url="$url_wiki$y$z"
  curl_f "$url" | sed -n '/^日付確定事項/,$p' | grep_f
  echo
done

echo "== 日時未確定 =="
curl_f "$url_planned" | grep_f

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?