Skip to content

Instantly share code, notes, and snippets.

@QB
Last active October 10, 2015 23:07
Show Gist options
  • Save QB/3764840 to your computer and use it in GitHub Desktop.
Save QB/3764840 to your computer and use it in GitHub Desktop.
EasyBotter で、現在のフォロワー一覧や、新規フォロー・リムーブを検知してメールする関数。 APIをページングできなかったり、 EasyBotter に依存していたりと、あまりにも糞なので、 ver 2.0 を作りました。使う場合はこちらをどうぞ→ http://gist.github.com/4618497
<?
//EasyBotter.php 内の class EasyBotter 内に新しい関数を突っ込むような感じで
function send($user,$address){
$f_list = $this->getFollowers();
for ( $i=0; $i < count($f_list); $i++){
$data[$i] = $f_list->user[$i]->screen_name;
}
sort($data);
$n_data= count($data); //フォロワー数を変数に代入しておく
for ( $j=0; $j < count($data); $j++){
$m_followers .= $j." => ".$data[$j]."\n";
$memo .= $data[$j]."\n";//これを今回のデータとして書き込む
}
$file = fopen("followers.dat","r");
$past = fread($file,filesize("followers.dat"));//前回のフォロワーデータを$pastに代入
fclose($file);
$file = fopen("followers.dat","w+");
fwrite($file,$memo); //前回のフォロワーデータは取り出したので、今回のものを上書きする
fclose($file);
$past = explode("\n",$past);
unset($past[count($past)-1]); //改行の関係で生じる最後の配列要素をカット
$n_past= count($past); //前回のフォロワー数を変数に代入しておく
for ( $k=0; $k < $n_data; $k++){
$appear="";
for ( $l=0; $l< $n_past; $l++){
if($past[$l] == $data[$k]) $appear .= "exist";
}
if(empty($appear)) $new_follower .= $this->name_link($data[$k])."\n";
}
for ( $m=0; $m < $n_past; $m++){
$appear="";
for ( $n=0; $n< $n_data; $n++){
if($past[$m] == $data[$n]) $appear .= "exist";
}
if(empty($appear)) $removed_follower .= $this->name_link($past[$m])."\n";
}
if(empty($new_follower)) $new_follower = "新規フォロワーはいません。\n";
if(empty($removed_follower)) $removed_follower = "新規リムーブはありません。\n";
$result = "\n新規フォローした人\n".$new_follower
."\n新規リムーブした人\n".$removed_follower
."\n■フォロワー数■\n現在:".$n_data." 前回:".$n_past
."\n-----\n*現在のフォロワー\n"
.$m_followers."-----\n".date("c")."\n";
mail($address,"フォロワー一覧".date("c"),$result);
echo "下記のメールを送信しますた。\n".$result;
}
function name_link($s){
return '<a href="http://twitter.com/'.$s.'" target="_blank">'.$s.'</a>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment