Skip to content

Instantly share code, notes, and snippets.

@seiyaKai
Last active December 10, 2015 06:08
Show Gist options
  • Save seiyaKai/4392415 to your computer and use it in GitHub Desktop.
Save seiyaKai/4392415 to your computer and use it in GitHub Desktop.
くっそ重いです。下手くそですが…Twitterのスクリーンネームの空きを検索してくれます。 $screen_names に検索したいスクリーンネームを入れていってください。 3文字IDとかいろいろ調べられるんじゃね〜みたいな?
<?php
$screen_names = array(); // 検索したいスクリーンネームをarrayのかたちで入れてください
for ($i=0 ; $i<10; $i++){
$screen_names[] = "hogepiyo".$i;
}
$tas = new TwitterAccountSearch();
$tas->Set($screen_names);
$tas->Search();
$tas->SearchResult();
$tas = NULL;
class TwitterAccountSearch{
private $accounts = array();
private $results = array();
public function __construct(){
echo "ようこそ\r\n";
}
public function __destruct(){
echo "さようなら\r\n";
}
public function Set($screen_names = array()){
foreach($screen_names as $value){
$this->accounts[] = array(
"SCREEN_NAME"=>$value,
"URL"=>"http://twitter.com/users/username_available?username=" . urlencode($value),
"VALID"=>NULL
);
unset($value);
}
return 0;
}
public function Search(){
echo "探索中...\r\n-------------\r\n";
$result = array();
foreach($this->accounts as $key => $value){
$ch = curl_init($value["URL"]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
$res = curl_exec($ch);
curl_close($ch);
$obj = json_decode($res,true);
$this->accounts[$key]["VALID"] = ($obj["valid"])?1:0;
if($this->accounts[$key]["VALID"] == 1){
$sn = $this->accounts[$key]["SCREEN_NAME"];
$this->results[] = $sn;
$this->WriteFile("./log.txt","a+",$sn."\r\n");
echo $sn." ...OK!\r\n";
}
unset($value);
}
echo "-------------\r\n探索完了!\r\n";
return $this->accounts;
}
public function SearchResult(){
print_r($this->results);
}
private function WriteFile($file_name,$mode,$text){
try{
$fp = fopen($file_name,$mode);
flock($fp, LOCK_EX);
fputs($fp,$text);
flock($fp, LOCK_UN);
fclose($fp);
}catch(Exception $e){
echo "oh...";
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment