Last active
December 11, 2015 15:08
-
-
Save QB/4618497 to your computer and use it in GitHub Desktop.
リムーブ検知プログラム ver 2.0
This file contains 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
<?php | |
require_once './tmhOAuth.php'; | |
/* | |
* ■ 設置方法 ■ | |
* 1, tmhOAuth.php をネットから拾ってきて、このファイルと同じディレクトリに置く。 | |
* 2, このファイルにある、下の設定項目を埋める。 | |
* 3, 鯖にうpして、cronで定期的に叩く。 | |
* | |
* 以上の手順でプログラムを動かすと、お好みの間隔で定期的にリムーブした者の一覧がメールで配信されます。 | |
*/ | |
/* ■↓■↓■↓■ 設定ここから ■↓■↓■↓■ */ | |
$file_name = "followers.dat"; //情報を格納するファイルの名前を設定 | |
define(ADDRESS, ""); //配信するメアドを設定 | |
/* トークンをセット */ | |
$tmh = new tmhOAuth(array( | |
'consumer_key' => '', | |
'consumer_secret' => '', | |
'user_token' => '', | |
'user_secret' => '', | |
'curl_ssl_verifypeer' => false, | |
)); | |
/* ■↑■↑■↑■ 設定ここまで ■↑■↑■↑■ */ | |
function m($s){ | |
mail(ADDRESS,"リムーブ検知プログラム",$s); | |
} | |
$present_followers = array();//フォロワーを格納するための変数を配列型にする | |
$page =0; | |
while($present_followers_source->next_cursor_str != "0"){ // cursorで回して情報を取る | |
if($page==0) $status = $tmh->request( "GET", $tmh->url("1.1/followers/list") ); | |
else $status = $tmh->request( "GET", $tmh->url("1.1/followers/list"), array("cursor"=>$present_followers_source->next_cursor_str) ); | |
$page = 1; | |
$present_followers_source = json_decode($tmh->response["response"]); | |
foreach ($present_followers_source->users as $present_followers_each) { | |
array_push($present_followers, $present_followers_each->screen_name); | |
} | |
} | |
sort($present_followers);//$present_followersはフォロワーのidが詰まった配列 | |
/* 現在のフォロワーの情報が準備できた */ | |
foreach($present_followers as $present_followers_each){ | |
$present_followers_text .= $present_followers_each."\n"; //保存するためのデータを生成 | |
} | |
if(!file_exists($file_name)){ //フォロワーを格納するファイルが無い場合には、現在のフォロワーをセットして終わり | |
file_put_contents($file_name, $present_followers_text); | |
m("フォロワーを取得しました。初期化完了"); | |
exit; | |
} | |
$past_followers_text = file_get_contents($file_name); //前回のフォロワーを取得 | |
file_put_contents($file_name, $present_followers_text); //前回のフォロワーを取り出し終わったので、現在のデータを保存する | |
$past_followers = explode("\n", $past_followers_text); //ファイルから取り出したものを分解 | |
unset($past_followers[count($past_followers)-1]); //改行の関係で生じる最後の配列要素をカット | |
$n_past = count($past_followers); | |
$n_present = count($present_followers); | |
/* 現在と過去のフォロワー情報、そしてそれらの人数がそろったので、これらを比較する */ | |
for($i=0; $i<$n_past; $i++) { //前回のフォロワー1人1人について | |
$check = ""; | |
foreach ($present_followers as $present_followers_each) { | |
if($past_followers[$i]==$present_followers_each) $check = "ok"; | |
} | |
if(empty($check)) $remover .= "http://twitter.com/".$past_followers[$i]."\n"; | |
} | |
if(empty($remover)) $remover = "いません"; // リムった人が居ない場合 | |
for($i=0; $i<$n_present; $i++) { //今回のフォロワー1人1人について | |
$check = ""; | |
foreach ($past_followers as $past_followers_each) { | |
if($present_followers[$i]==$past_followers_each) $check = "ok"; | |
} | |
if(empty($check)) $newer .= "http://twitter.com/".$present_followers[$i]."\n"; | |
} | |
if(empty($newer)) $newer = "いません"; | |
// メールで送る用に、$present_followsers に番号を付記して整形する | |
$send_text = "■新規リムーブした人■\n".$remover."\n====\n" | |
."■新規フォローした人■\n".$newer."\n====\n" | |
.print_r($present_followers, true); | |
m($send_text); | |
echo $send_text; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment