5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

千葉県の停電情報が気になりすぎたのでGASでスクレイピングしてSlackに投げてみた

Last updated at Posted at 2019-09-12

昨晩のゲリラ雷雨で一時的に軒数増えたりしてずっと気になってた
TEPCO停電情報の千葉県のページ

結構な勢いで復旧してるので現場の方お疲れ様です。
定期的にF5押して見てたけどめんどくさいのでスクライピングして件数を取ってこようという考えに
以下をパク参考にさせていただきました

【GoogleAppsScript】【Slack】電車遅延情報post


function teidenInfo() {
 
  var yahoo = "http://teideninfo.tepco.co.jp/html/12000000000.html";
  var response = UrlFetchApp.fetch(yahoo);
  var myRegexp_line = /<div id="area_right">([\s\S]*?)<\/div>/i;
  var line_html = myRegexp_line.exec(response.getContentText("shift-jis"));
  var line_list = line_html[0];
  
  var now = new Date();  
  var time = Utilities.formatDate(now, 'Asia/Tokyo', 'yyyy/MM/dd HH:mm:ss');
  
  // 文字の整形
  var line_base = line_list.replace(/<("[^"]*"|'[^']*'|[^'">])*>/g,'')
  var line = "千葉県:" + time + " 現在\n" + line_base
 
    function postMessage(message, hookPoint){
    var payload = {
      "text": message,
      "channelId": '#information',
      "userName": 'train-info',
      "icon_emoji": ':train:'
    }
    var options = {
      "method": "POST",
      "payload": JSON.stringify(payload),
      "headers": {
      "Content-type": "application/json",
      }
    }
    var response = UrlFetchApp.fetch(hookPoint, options);

    if (response.getResponseCode() == 200) {
      return response;
    }
      return false;
  }
    postMessage("```" + line  + "```",'https://hooks.slack.com/services/[SLACKのソレ]');
}

あとはほっとくと以下のように定期的に件数をSlackに吐いてくれます、アイコンは参考元そのまま

スクリーンショット 2019-09-12 10.31.33.png

5
4
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
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?