├── .gitignore ├── .gitmodules ├── README.md ├── config-default.php ├── log └── .gitkeep ├── tmp └── .gitkeep └── twitter_bot.php /.gitignore: -------------------------------------------------------------------------------- 1 | /tmp/ 2 | /log/ 3 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "twitteroauth"] 2 | path = twitteroauth 3 | url = https://github.com/abraham/twitteroauth.git 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | chatwork_isdead 2 | =============== 3 | 4 | chatwork is dead... - twitter bot 5 | 6 | チャットワークは死んだボットです。 7 | チャットワークが死んだらTwitterでお知らせします。 8 | 息を吹き返してもお知らせします。 9 | 10 | https://twitter.com/chatwork_isdead 11 | 12 | 作った人=運用してる人: [M_Ishikawa](http://about.me/M_Ishikawa) 13 | -------------------------------------------------------------------------------- /config-default.php: -------------------------------------------------------------------------------- 1 | '', 9 | 'consumer_secret' => '', 10 | 'access_token' => '', 11 | 'access_token_secret' => '', 12 | ); 13 | return $config; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /log/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishikawam/chatwork_isdead/84bfb49cdc0c72a7992c16d13a13d60299f6e480/log/.gitkeep -------------------------------------------------------------------------------- /tmp/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishikawam/chatwork_isdead/84bfb49cdc0c72a7992c16d13a13d60299f6e480/tmp/.gitkeep -------------------------------------------------------------------------------- /twitter_bot.php: -------------------------------------------------------------------------------- 1 | array( 7 | 'method' => 'GET', 8 | 'ignore_errors' => true, // エラーページも内容取得 9 | 'timeout' => 10, 10 | ) 11 | ) 12 | ); 13 | 14 | require('config.php'); 15 | $config = Config::getConfig(); 16 | 17 | /********************************************************/ 18 | 19 | // Chatwork KDDI版をチェック 20 | $res = file_get_contents('https://kcw.kddi.ne.jp', false, $context); 21 | // 200で'

ログイン

'があれば正常としておく 22 | 23 | file_put_contents(dirname(__FILE__) . '/tmp/res_header_page', print_r($http_response_header, true)); 24 | file_put_contents(dirname(__FILE__) . '/tmp/content_page', $res); 25 | 26 | preg_match_all('/^HTTP\/[^ ]+ ([0-9]{3})/m', implode("\n" ,$http_response_header), $matches); 27 | $status_code = array_pop($matches[1]); // リダイレクトとかされる場合もあるので最後のstatusを取る 28 | if (!$res || $status_code != 200) { 29 | tweet('チャットワーク(KDDI版)は死んだ', 'page'); 30 | } else if (preg_match('|

Log in with email address

|', $res) === false) { 31 | tweet('チャットワーク(KDDI版)は死んだかもしれない', 'page'); 32 | } else { 33 | tweet('チャットワーク(KDDI版)は蘇った!!!', 'page'); 34 | } 35 | 36 | /********************************************************/ 37 | 38 | // Chatwork本家をチェック 39 | $res = file_get_contents('https://www.chatwork.com', false, $context); 40 | // 200で'

ログイン

'があれば正常としておく 41 | 42 | file_put_contents(dirname(__FILE__) . '/tmp/res_header_www', print_r($http_response_header, true)); 43 | file_put_contents(dirname(__FILE__) . '/tmp/content_www', $res); 44 | 45 | preg_match_all('/^HTTP\/[^ ]+ ([0-9]{3})/m', implode("\n" ,$http_response_header), $matches); 46 | $status_code = array_pop($matches[1]); // リダイレクトとかされる場合もあるので最後のstatusを取る 47 | if (!$res || $status_code != 200) { 48 | tweet('チャットワークは死んだ', 'www'); 49 | } else if (preg_match('|

Log in with email address

|', $res) === false) { 50 | tweet('チャットワークは死んだかもしれない', 'www'); 51 | } else { 52 | tweet('チャットワークは蘇った!!!', 'www'); 53 | } 54 | 55 | /********************************************************/ 56 | 57 | $res = file_get_contents('https://api.chatwork.com/', false, $context); 58 | // 401で'{"errors":["Invalid API token"]}'なら正常としておく。 59 | 60 | file_put_contents(dirname(__FILE__) . '/tmp/res_header_api', print_r($http_response_header, true)); 61 | file_put_contents(dirname(__FILE__) . '/tmp/content_api', $res); 62 | 63 | preg_match_all('/^HTTP\/[^ ]+ ([0-9]{3})/m', implode("\n" ,$http_response_header), $matches); 64 | $status_code = array_pop($matches[1]); // リダイレクトとかされる場合もあるので最後のstatusを取る 65 | 66 | if (!$res || $status_code != 401) { 67 | tweet('チャットワークAPIは死んだ', 'api'); 68 | } else if ($res != '{"errors":["Invalid API token"]}') { 69 | tweet('チャットワークAPIは死んだかもしれない', 'api'); 70 | } else { 71 | tweet('チャットワークAPIは蘇った!!!', 'api'); 72 | } 73 | 74 | /********************************************************/ 75 | 76 | // つぶやく 77 | function tweet($message, $type = '') { 78 | $message .= ' #chatwork'; 79 | $status = @file_get_contents(dirname(__FILE__) . '/tmp/status_' . $type); 80 | 81 | if ($status && $message == $status) { 82 | return; 83 | } 84 | 85 | file_put_contents(dirname(__FILE__) . '/log/tweet_' . $type . '_log', date('Y-m-d H:i:s', time()) . ' ' . $message . "\n", FILE_APPEND); 86 | file_put_contents(dirname(__FILE__) . '/tmp/status_' . $type, $message); 87 | 88 | $config = Config::getConfig(); 89 | $connection = new TwitterOAuth( 90 | $config['consumer_key'], 91 | $config['consumer_secret'], 92 | $config['access_token'], 93 | $config['access_token_secret'] 94 | ); 95 | 96 | // return; // for debug 97 | $req = $connection->OAuthRequest('https://api.twitter.com/1.1/statuses/update.json', 'POST', array('status' => $message )); 98 | 99 | // ついでに自分にメール 100 | mb_internal_encoding('UTF-8'); 101 | mb_send_mail('ishikawam@nifty.com', $message, $message . "\n\nhttps://twitter.com/chatwork_isdead\n"); 102 | } 103 | --------------------------------------------------------------------------------