Last active
November 26, 2019 15:05
-
-
Save orimajp/5112fe17a9dce3b8f1e388dd1f08290a to your computer and use it in GitHub Desktop.
運行情報GAS暫定スクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var TARGET_LINES = [ | |
// [JR東日本] | |
// 東海道方面 | |
{name: '東海道線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '京浜東北線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '横須賀線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '南武線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '横浜線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '伊東線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '相模線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '鶴見線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
// 東北・高崎方面 | |
{name: '宇都宮線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '高崎線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
// {name: '京浜東北線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, // 重複しているので除外 | |
{name: '埼京線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '川越線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '武蔵野線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '上越線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '信越本線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
// {name: '吾妻線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '烏山線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
// {name: '八高線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '日光線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
// {name: '両毛線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
// 中央方面 | |
{name: '中央線快速電車', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '中央線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '中央本線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '中央・総武各駅停車', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '武蔵野線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '五日市線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '青梅線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
// {name: '八高線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '小海線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
// 常磐方面 | |
{name: '常磐線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '常磐線快速電車', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '常磐線各駅停車', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
// {name: '水郡線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '水戸線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
// 総武方面 | |
{name: '総武快速線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '総武本線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '中央・総武各駅停車', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '京葉線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '武蔵野線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '内房線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '鹿島線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '久留里線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '外房線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '東金線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '成田線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
// 山手線 | |
{name: '山手線', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
// 直通サービス | |
{name: '上野東京ライン', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
{name: '湘南新宿ライン', company: 'JR東日本', website: 'https://traininfo.jreast.co.jp/train_info/kanto.aspx'}, | |
// [東京メトロ] | |
{name: '銀座線', company: '東京メトロ', website: 'https://www.tokyometro.jp/unkou/history/ginza.html'}, | |
{name: '丸ノ内線', company: '東京メトロ', website: 'https://www.tokyometro.jp/unkou/history/marunouchi.html'}, | |
{name: '日比谷線', company: '東京メトロ', website: 'https://www.tokyometro.jp/unkou/history/hibiya.html'}, | |
{name: '東西線', company: '東京メトロ', website: 'https://www.tokyometro.jp/unkou/history/touzai.html'}, | |
{name: '千代田線', company: '東京メトロ', website: 'https://www.tokyometro.jp/unkou/history/chiyoda.html'}, | |
{name: '有楽町線', company: '東京メトロ', website: 'https://www.tokyometro.jp/unkou/history/yurakucho.html'}, | |
{name: '半蔵門線', company: '東京メトロ', website: 'https://www.tokyometro.jp/unkou/history/hanzoumon.html'}, | |
{name: '南北線', company: '東京メトロ', website: 'https://www.tokyometro.jp/unkou/history/nanboku.html'}, | |
{name: '副都心線', company: '東京メトロ', website: 'https://www.tokyometro.jp/unkou/history/fukutoshin.html'}, | |
{name: '東葉高速線', company: '東京メトロ', website: 'http://www.toyokosoku.co.jp/'}, | |
{name: '埼玉高速鉄道線', company: '東京メトロ', website: 'https://www.s-rail.co.jp/train/'}, | |
{name: '東京メトロ南北線', company: '東京メトロ', website: 'https://www.tokyometro.jp/unkou/history/nanboku.html'}, | |
// [都営地下鉄] | |
{name: '浅草線', company: '都営地下鉄', website: 'https://www.kotsu.metro.tokyo.jp/subway/schedule/index.html'}, | |
{name: '三田線', company: '都営地下鉄', website: 'https://www.kotsu.metro.tokyo.jp/subway/schedule/index.html'}, | |
{name: '新宿線', company: '都営地下鉄', website: 'https://www.kotsu.metro.tokyo.jp/subway/schedule/index.html'}, | |
{name: '大江戸線', company: '都営地下鉄', website: 'https://www.kotsu.metro.tokyo.jp/subway/schedule/index.html'}, | |
{name: '都営新宿線', company: '都営地下鉄', website: 'https://www.kotsu.metro.tokyo.jp/subway/schedule/index.html'}, | |
// [東武鉄道] | |
{name: '東上本線', company: '東武鉄道', website: 'http://tra-rep.tobu.jp/index.html'}, | |
{name: '東武線', company: '東武鉄道', website: 'http://tra-rep.tobu.jp/index.html'}, | |
{name: '東武特急', company: '東武鉄道', website: 'http://tra-rep.tobu.jp/index.html'}, | |
{name: '東武アーバンパークライン', company: '東武鉄道', website: 'http://tra-rep.tobu.jp/index.html'}, | |
{name: '日光線特急', company: '東武鉄道', website: 'http://tra-rep.tobu.jp/index.html'}, | |
{name: '伊勢崎線特急', company: '東武鉄道', website: 'http://tra-rep.tobu.jp/index.html'}, | |
{name: '東武スカイツリーライン・伊勢崎線', company: '東武鉄道', website: 'http://tra-rep.tobu.jp/index.html'}, | |
{name: '東武スカイツリーライン', company: '東武鉄道', website: 'http://tra-rep.tobu.jp/index.html'}, | |
{name: '伊勢崎線', company: '東武鉄道', website: 'http://tra-rep.tobu.jp/index.html'}, | |
{name: '伊勢崎線特急', company: '東武鉄道', website: 'http://tra-rep.tobu.jp/index.html'}, | |
{name: '東武日光線', company: '東武鉄道', website: 'http://tra-rep.tobu.jp/index.html'}, | |
{name: '小泉線', company: '東武鉄道', website: 'http://tra-rep.tobu.jp/index.html'}, | |
{name: '亀戸線', company: '東武鉄道', website: 'http://tra-rep.tobu.jp/index.html'}, | |
{name: '大師線', company: '東武鉄道', website: 'http://tra-rep.tobu.jp/index.html'}, | |
{name: '特急りょうもう', company: '東武鉄道', website: 'http://tra-rep.tobu.jp/index.html'}, | |
{name: '特急スペーシア', company: '東武鉄道', website: 'http://tra-rep.tobu.jp/index.html'}, | |
{name: '東上本線', company: '東武鉄道', website: 'http://tra-rep.tobu.jp/index.html'}, | |
{name: '越生線', company: '東武鉄道', website: 'http://tra-rep.tobu.jp/index.html'}, | |
{name: '佐野線', company: '東武鉄道', website: 'http://tra-rep.tobu.jp/index.html'}, | |
{name: '鬼怒川線', company: '東武鉄道', website: 'http://tra-rep.tobu.jp/index.html'}, | |
{name: '桐生線', company: '東武鉄道', website: 'http://tra-rep.tobu.jp/index.html'}, | |
// [西武鉄道] | |
{name: '西武線', company: '西武鉄道', website: 'https://www.seiburailway.jp/railwayinfo/index.html'}, | |
{name: '池袋線', company: '西武鉄道', website: 'https://www.seiburailway.jp/railwayinfo/index.html'}, | |
{name: '西武秩父線', company: '西武鉄道', website: 'https://www.seiburailway.jp/railwayinfo/index.html'}, | |
{name: '西武有楽町線', company: '西武鉄道', website: 'https://www.seiburailway.jp/railwayinfo/index.html'}, | |
{name: '西武新宿線', company: '西武鉄道', website: 'https://www.seiburailway.jp/railwayinfo/index.html'}, | |
{name: '豊島線', company: '西武鉄道', website: 'https://www.seiburailway.jp/railwayinfo/index.html'}, | |
{name: '狭山線', company: '西武鉄道', website: 'https://www.seiburailway.jp/railwayinfo/index.html'}, | |
{name: '新宿線', company: '西武鉄道', website: 'https://www.seiburailway.jp/railwayinfo/index.html'}, | |
{name: '拝島線', company: '西武鉄道', website: 'https://www.seiburailway.jp/railwayinfo/index.html'}, | |
{name: '多摩湖線', company: '西武鉄道', website: 'https://www.seiburailway.jp/railwayinfo/index.html'}, | |
{name: '国分寺線', company: '西武鉄道', website: 'https://www.seiburailway.jp/railwayinfo/index.html'}, | |
{name: '西武園線', company: '西武鉄道', website: 'https://www.seiburailway.jp/railwayinfo/index.html'}, | |
{name: '多摩川線', company: '西武鉄道', website: 'https://www.seiburailway.jp/railwayinfo/index.html'}, | |
{name: '特急レッドアロー', company: '西武鉄道', website: 'https://www.seiburailway.jp/railwayinfo/index.html'}, | |
{name: '山口線', company: '西武鉄道', website: 'https://www.seiburailway.jp/railwayinfo/index.html'}, | |
{name: 'S-TRAIN', company: '西武鉄道', website: 'https://www.seiburailway.jp/railwayinfo/index.html'}, | |
// [京成電鉄] | |
{name: '京成線', company: '京成電鉄', website: 'http://www.keisei.co.jp/info/index.htm'}, | |
{name: '京成本線', company: '京成電鉄', website: 'http://www.keisei.co.jp/info/index.htm'}, | |
{name: '東成田線', company: '京成電鉄', website: 'http://www.keisei.co.jp/info/index.htm'}, | |
{name: '芝山鉄道線', company: '京成電鉄', website: 'http://www.keisei.co.jp/info/index.htm'}, | |
{name: '成田スカイアクセス線', company: '京成電鉄', website: 'http://www.keisei.co.jp/info/index.htm'}, | |
{name: '特急スカイライナー', company: '京成電鉄', website: 'http://www.keisei.co.jp/info/index.htm'}, | |
{name: '北総線', company: '京成電鉄', website: 'http://www.keisei.co.jp/info/index.htm'}, | |
{name: '押上線', company: '京成電鉄', website: 'http://www.keisei.co.jp/info/index.htm'}, | |
{name: '金町線', company: '京成電鉄', website: 'http://www.keisei.co.jp/info/index.htm'}, | |
{name: '千葉線', company: '京成電鉄', website: 'http://www.keisei.co.jp/info/index.htm'}, | |
{name: '千原線', company: '京成電鉄', website: 'http://www.keisei.co.jp/info/index.htm'}, | |
// [新京成電鉄] | |
{name: '新京成線', company: '新京成電鉄', website: 'https://www.shinkeisei.co.jp/train/rail_info/'}, | |
// [京王電鉄] | |
{name: '京王線', company: '京王電鉄', website: 'https://www.keio.co.jp/unkou/unkou_pc.html'}, | |
{name: '井の頭線', company: '京王電鉄', website: 'https://www.keio.co.jp/unkou/unkou_pc.html'}, | |
// [小田急電鉄] | |
{name: '小田急線', company: '小田急電鉄', website: 'https://www.odakyu.jp/cgi-bin/user/emg/emergency_bbs.pl'}, | |
{name: '小田急特急', company: '小田急電鉄', website: 'https://www.odakyu.jp/cgi-bin/user/emg/emergency_bbs.pl'}, | |
{name: '特急電車', company: '小田急電鉄', website: 'https://www.odakyu.jp/cgi-bin/user/emg/emergency_bbs.pl'}, | |
{name: '小田原線', company: '小田急電鉄', website: 'https://www.odakyu.jp/cgi-bin/user/emg/emergency_bbs.pl'}, | |
{name: '江ノ島線', company: '小田急電鉄', website: 'https://www.odakyu.jp/cgi-bin/user/emg/emergency_bbs.pl'}, | |
{name: '多摩線', company: '小田急電鉄', website: 'https://www.odakyu.jp/cgi-bin/user/emg/emergency_bbs.pl'}, | |
{name: '特急ロマンスカー', company: '小田急電鉄', website: 'https://www.odakyu.jp/cgi-bin/user/emg/emergency_bbs.pl'}, | |
// [東急電鉄] | |
{name: '東横線', company: '東急電鉄', website: 'https://www.tokyu.co.jp/unten2/unten.html'}, | |
{name: '目黒線', company: '東急電鉄', website: 'https://www.tokyu.co.jp/unten2/unten.html'}, | |
{name: '田園都市線', company: '東急電鉄', website: 'https://www.tokyu.co.jp/unten2/unten.html'}, | |
{name: '大井町線', company: '東急電鉄', website: 'https://www.tokyu.co.jp/unten2/unten.html'}, | |
{name: '東急多摩川線', company: '東急電鉄', website: 'https://www.tokyu.co.jp/unten2/unten.html'}, | |
{name: '池上線', company: '東急電鉄', website: 'https://www.tokyu.co.jp/unten2/unten.html'}, | |
{name: 'こどもの国線', company: '東急電鉄', website: 'https://www.tokyu.co.jp/unten2/unten.html'}, | |
{name: '世田谷線', company: '東急電鉄', website: 'https://www.tokyu.co.jp/unten2/unten.html'}, | |
{name: 'みなとみらい線', company: '東急電鉄', website: 'https://www.mm21railway.co.jp/service/'}, | |
// [京急電鉄] | |
{name: '京急線', company: '京急電鉄', website: 'https://unkou.keikyu.co.jp/'}, | |
{name: '空港線', company: '京急電鉄', website: 'https://unkou.keikyu.co.jp/'}, | |
{name: '大師線', company: '京急電鉄', website: 'https://unkou.keikyu.co.jp/'}, | |
{name: '逗子線', company: '京急電鉄', website: 'https://unkou.keikyu.co.jp/'}, | |
{name: '久里浜線', company: '京急電鉄', website: 'https://unkou.keikyu.co.jp/'}, | |
// [相模鉄道] | |
{name: '相鉄線', company: '相模鉄道', website: 'https://www.sotetsu.co.jp/train/status/'}, | |
// [新京成電鉄] | |
{name: '新京成線', company: '新京成電鉄', website: 'https://www.shinkeisei.co.jp/train/rail_info/'}, | |
// [横浜市交通局] | |
{name: '横浜市営地下鉄', company: '横浜市交通局', website: 'https://www.city.yokohama.lg.jp/kotsu/'}, | |
// [横浜市営地下鉄] | |
{name: 'ブルーライン', company: '横浜市営地下鉄', website: 'https://www.city.yokohama.lg.jp/kotsu/'}, | |
{name: 'グリーンライン', company: '横浜市営地下鉄', website: 'https://www.city.yokohama.lg.jp/kotsu/'}, | |
// [りんかい線] | |
{name: 'りんかい線', company: 'りんかい線', website: 'https://service.twr.co.jp/service_info/information.html'}, | |
// [つくばエクスプレス] | |
{name: 'つくばエクスプレス線', company: 'つくばエクスプレス', website: 'http://www.mir.co.jp/info/'}, | |
// [関東鉄道] | |
{name: '常総線', company: '関東鉄道', website: 'http://www.kantetsu.co.jp/unkouinfo/details.cgi'}, | |
{name: '竜ヶ崎線', company: '関東鉄道', website: 'http://www.kantetsu.co.jp/unkouinfo/details.cgi'}, | |
// [ゆりかもめ] | |
{name: 'ゆりかもめ', company: 'ゆりかもめ', website: 'https://www.yurikamome.co.jp/ride-guidance/operation.html'}, | |
// [東京モノレール] | |
{name: '東京モノレール', company: '東京モノレール', website: 'http://www.tokyo-monorail.co.jp/guidance/'}, | |
// [日暮里・舎人ライナー] | |
{name: '日暮里・舎人ライナー', company: '日暮里・舎人ライナー', website: 'https://www.kotsu.metro.tokyo.jp/nippori_toneri/schedule/'}, | |
// [千葉モノレール] | |
{name: '千葉モノレール', company: '千葉モノレール', website: 'https://chiba-monorail.co.jp/index.php/info-detail/'}, | |
// [多摩モノレール] | |
{name: '多摩モノレール', company: '多摩モノレール', website: 'https://www.tama-monorail.co.jp/monorail/operation/index.html'}, | |
// [横浜シーサイドライン] | |
{name: 'シーサイドライン', company: '横浜シーサイドライン', website: 'https://www.seasideline.co.jp/guidance/train_info/'}, | |
{name: '金沢シーサイドライン', company: '横浜シーサイドライン', website: 'https://www.seasideline.co.jp/guidance/train_info/'}, | |
// [湘南モノレール] | |
{name: '湘南モノレール', company: '湘南モノレール', website: 'http://www.shonan-monorail.co.jp/'}, | |
// [ニューシャトル] | |
{name: 'ニューシャトル', company: 'ニューシャトル', website: 'http://www.new-shuttle.jp/'}, | |
// [真岡鐵道] | |
{name: '真岡線', company: '真岡鐵道', website: 'http://www.moka-railway.co.jp/'}, | |
// [小湊鉄道] | |
// {name: '小湊鉄道線', company: '小湊鉄道', website: 'https://www.kominato.co.jp/train/index.html'}, | |
// [銚子電気鉄道] | |
{name: '銚子電気鉄道線', company: '銚子電気鉄道', website: 'https://www.choshi-dentetsu.jp/'}, | |
// [鹿島臨海鉄道] | |
{name: '大洗鹿島線', company: '鹿島臨海鉄道', website: 'https://www.rintetsu.co.jp/'}, | |
// [富士急行] | |
{name: '富士急行線', company: '富士急行', website: 'http://www.fujikyu-railway.jp/'}, | |
// [伊豆急行] | |
{name: '伊豆急行線', company: '伊豆急行', website: 'https://www.izukyu.co.jp/'}, | |
// [上信電鉄] | |
{name: '上信線', company: '上信電鉄', website: 'https://www.joshin-dentetsu.co.jp/'}, | |
// [上毛電気鉄道] | |
{name: '上毛線', company: '上毛電気鉄道', website: 'http://www.jomorailway.com/'}, | |
]; | |
var PARAMETER_LISTS = [ | |
{param: 'jr', companies: [{company: 'JR東日本'}], description: 'JR東日本'}, | |
{param: 'metro', companies: [{company: '東京メトロ'}], description: '東京メトロ'}, | |
{param: 'toei', companies: [{company: '都営地下鉄'}], description: '都営地下鉄'}, | |
{param: 'tobu', companies: [{company: '東武鉄道'}], description: '東武鉄道'}, | |
{param: 'seibu', companies: [{company: '西武鉄道'}], description: '西武鉄道'}, | |
{param: 'keisei', companies: [{company: '京成電鉄'}], description: '京成電鉄'}, | |
{param: 'shinkeisei', companies: [{company: '新京成電鉄'}], description: '新京成電鉄'}, | |
{param: 'keio', companies: [{company: '京王電鉄'}], description: '京王電鉄'}, | |
{param: 'odakyu', companies: [{company: '小田急電鉄'}], description: '小田急電鉄'}, | |
{param: 'tokyu', companies: [{company: '東急電鉄'}], description: '東急電鉄'}, | |
{param: 'keikyu', companies: [{company: '京急電鉄'}], description: '京急電鉄(みなとみらい線含む)'}, | |
{param: 'sotetsu', companies: [{company: '相模鉄道'}], description: '相模鉄道'}, | |
{param: 'shinkeisei', companies: [{company: '新京成電鉄'}], description: '新京成電鉄'}, | |
{param: 'yokohama', companies: [{company: '横浜市交通局'}, {company: '横浜市営地下鉄'}], description: '横浜市営地下鉄'}, | |
{param: 'rinkai', companies: [{company: 'りんかい線'}], description: 'りんかい線'}, | |
{param: 'tsukuba', companies: [{company: 'つくばエクスプレス'}], description: 'つくばエクスプレス'}, | |
{param: 'kantetsu', companies: [{company: '関東鉄道'}], description: '関東鉄道'}, | |
{param: 'yurikamome', companies: [{company: 'ゆりかもめ'}], description: 'ゆりかもめ'}, | |
{param: 'tokyomono', companies: [{company: '東京モノレール'}], description: '東京モノレール'}, | |
{param: 'nippori', companies: [{company: '日暮里・舎人ライナー'}], description: '日暮里・舎人ライナー'}, | |
{param: 'chibamono', companies: [{company: '千葉モノレール'}], description: '千葉モノレール'}, | |
{param: 'tamamono', companies: [{company: '多摩モノレール'}], description: '多摩モノレール'}, | |
{param: 'yokohama', companies: [{company: '横浜シーサイドライン'}], description: '横浜シーサイドライン'}, | |
{param: 'shonan', companies: [{company: '湘南モノレール'}], description: '湘南モノレール'}, | |
{param: 'nyu', companies: [{company: 'ニューシャトル'}], description: 'ニューシャトル'}, | |
{param: 'moka', companies: [{company: '真岡鐵道'}], description: '真岡鐵道'}, | |
{param: 'kominato', companies: [{company: '小湊鉄道'}], description: '小湊鉄道(現在運行情報取得対象外)'}, | |
{param: 'choshi', companies: [{company: '銚子電気鉄道'}], description: '銚子電気鉄道'}, | |
{param: 'kashima', companies: [{company: '鹿島臨海鉄道'}], description: '鹿島臨海鉄道'}, | |
{param: 'fujikyu', companies: [{company: '富士急行'}], description: '富士急行'}, | |
{param: 'izukyu', companies: [{company: '伊豆急行'}], description: '伊豆急行'}, | |
{param: 'joshin', companies: [{company: '上信電鉄'}], description: '上信電鉄'}, | |
{param: 'jomo', companies: [{company: '上毛電気鉄道'}], description: '上毛電気鉄道'}, | |
]; | |
var token = '***************************'; // トークン | |
var url = 'https://tetsudo.rti-giken.jp/free/delay.json'; | |
function doPost(e) { | |
var verificationToken = e.parameter.token; | |
if (verificationToken !== token) { | |
throw new Error('Invalid token'); | |
} | |
var parameter = e.parameter.text; | |
var targetLine = null; | |
if (parameter !== '') { | |
targetLine = gerTargetLine(parameter); | |
if (parameter === 'help' || targetLine === null) { | |
var additionalMessage = getAdditionalHelpMessage(parameter); | |
var helpResponse = createHelpRespnse(additionalMessage); | |
return ContentService.createTextOutput(JSON.stringify(helpResponse)).setMimeType(ContentService.MimeType.JSON); | |
} | |
} | |
var options = { | |
"muteHttpExceptions" : true, //エラー捕捉 | |
"validateHttpsCertificates" : false, //証明書エラー回避 | |
"followRedirects" : false, //リダイレクト先捕捉 | |
} | |
var message = ''; // JavaScriptの場合、varで定義した変数のスコープはグローバルか関数なのでtry内に書いても大丈夫な気はする。 | |
try { | |
var response = UrlFetchApp.fetch(url, options); | |
var responseCode = response.getResponseCode(); | |
var responseBody = response.getContentText(); | |
if (responseCode === 200) { | |
var json = JSON.parse(response); | |
var delayArray = analyzeJson(json, targetLine); | |
message = createMessage(delayArray, targetLine); | |
} else { | |
Logger.log(Utilities.formatString("Request failed. Expected 200, got %d: %s", responseCode, responseBody)); | |
var errorMessage = '通信エラーが発生しました。 HTTP status: ' + responseCode; | |
message = {title: errorMessage, detail: ''}; | |
} | |
} catch(e) { | |
Logger.log("message:" + e.message + "\nfileName:" + e.fileName + "\nlineNumber:" + e.lineNumber + "\nstack:" + e.stack); | |
var errorMessage = '通信エラーが発生しました。 message: ' + e.message; | |
message = {title: errorMessage, detail: ''}; | |
} | |
var response = createResponse(message); | |
return ContentService.createTextOutput(JSON.stringify(response)).setMimeType(ContentService.MimeType.JSON); | |
} | |
function gerTargetLine(parameter) { | |
for each (var obj in PARAMETER_LISTS) { | |
if (parameter === obj.param) { | |
return obj; | |
} | |
} | |
return null; | |
} | |
function matchLineName(targetLine, company) { | |
if (targetLine === null) { | |
return true; | |
} | |
for each (var obj in targetLine.companies) { | |
if (obj.company === company) { | |
return true; | |
} | |
} | |
return false; | |
} | |
function delayArraySort(line1, line2) { | |
var company1 = line1.company; | |
var company2 = line2.company; | |
if (company1 < company2) { | |
return -1; | |
} | |
if (company1 > company2) { | |
return 1; | |
} | |
return 0; | |
} | |
function analyzeJson(json, targetLine) { | |
var delayArray = []; | |
for each (var obj in json) { | |
for each (var line in TARGET_LINES) { | |
if (matchLineName(targetLine, obj.company) && obj.name === line.name && obj.company === line.company) { | |
delayArray.push(line); | |
} | |
} | |
} | |
return delayArray.slice(0).sort(delayArraySort); | |
} | |
function getLineDescription(targetLine) { | |
if (targetLine === null) { | |
return null; | |
} | |
return targetLine.description; | |
} | |
function createMessage(delayInfoArray, targetLine) { | |
var description = getLineDescription(targetLine); | |
var additionalNoDataTitle = description === null ? '' : description + 'は'; | |
if (delayInfoArray.length === 0) { | |
return {title: additionalNoDataTitle + '平常運転中です。', detail: ''} | |
} | |
var details = []; | |
for each (var obj in delayInfoArray) { | |
details.push('・' + obj.company + ': ' + obj.name + ': <' + obj.website + '|こちら>'); | |
} | |
var additionalExistDataTitle = description === null ? '' : description + 'に'; | |
return {title: additionalExistDataTitle + '運行情報があります。', detail : details.join('\n')}; | |
} | |
function createResponse(message) { | |
if (message.detail === '') { | |
return { | |
attachments: [ | |
{ | |
'pretext': message.title, | |
} | |
] | |
}; | |
} | |
return { | |
attachments: [ | |
{ | |
'color': '#36a64f', | |
'pretext': message.title, | |
'text': message.detail | |
} | |
] | |
}; | |
} | |
function createHelpRespnse(additionalMessage) { | |
var helpTitle = additionalMessage + '運行情報コマンドの利用方法は以下の通りです。'; | |
var helpMessage = createHelpTitle() + createHelpDetail(); | |
return { | |
attachments: [ | |
{ | |
'pretext': helpTitle, | |
'text': helpMessage | |
} | |
] | |
}; | |
} | |
function createHelpTitle() { | |
var helpTitle = | |
'/unkou\n' + | |
'/unkou パラメータ ※パラメータに対応する路線の運行情報を検索\n' + | |
'/unkou help ※このメッセージを表示\n\n' + | |
'※存在しないパラメータが指定された場合このメッセージが表示されます。\n\n'; | |
return helpTitle; | |
} | |
function createHelpDetail() { | |
var helpDetail = 'パラメータ 対象路線\n'; | |
for each (var obj in PARAMETER_LISTS) { | |
helpDetail += obj.param + ' ' + obj.description + '\n'; | |
} | |
return helpDetail; | |
} | |
function getAdditionalHelpMessage(parameter) { | |
if (parameter === 'help') { | |
return ''; | |
} | |
return '指定されたパラメータが誤っています。 パラメータ: ' + parameter + '\n'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment