Created
September 1, 2014 16:00
-
-
Save m77so/89b2ed4aafbc1f7b1b4c to your computer and use it in GitHub Desktop.
This file contains hidden or 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('UltimateOAuth_530.php'); | |
| require_once('config.php') | |
| $uo=new UltimateOAuth(KY,KS,AT,AS); | |
| function id2time($id){ | |
| $i=22; | |
| while($i--){ | |
| $id=bcsub($id,bcmod($id,2)); | |
| $id=bcdiv($id,'2',0); | |
| } | |
| $id = bcadd($id,'1288834974657'); | |
| return $id; | |
| } | |
| function time_diff($str1,$str2){ | |
| $str1 = id2time($str1); | |
| $str2 = id2time($str2); | |
| $res =abs(intval(bcsub($str1,$str2))); | |
| return $res; | |
| } | |
| function input_if_not_null($target,$var){ | |
| if($target==NULL){return $var;}else{return $target;} | |
| } | |
| $res=$uo->get('statuses/user_timeline'); | |
| $irt = array(); | |
| foreach($res as $status){ | |
| if(isset($status->in_reply_to_status_id_str)){ | |
| array_push($irt,$status->in_reply_to_status_id_str); | |
| } | |
| } | |
| $res=$uo->get('statuses/mentions_timeline'); | |
| if(isset($res)){ | |
| foreach($res as $status){ | |
| if(!(in_array($status->id_str,$irt))){ | |
| $tweet=""; | |
| $user_id = $status->user->id_str; | |
| $res_user=$uo->get('statuses/user_timeline',array( | |
| 'user_id' => $user_id | |
| )); | |
| $char_time = array(); | |
| foreach($res_user as $status_user){ | |
| if($status_user->text == "か"){$char_time['か']=input_if_not_null($char_time['か'],$status_user->id_str);} | |
| if($status_user->text == "そ"){$char_time['そ']=input_if_not_null($char_time['そ'],$status_user->id_str);} | |
| if($status_user->text == "く"){$char_time['く']=input_if_not_null($char_time['く'],$status_user->id_str);} | |
| if(count($char_time)>2){break;} | |
| } | |
| if(count($char_time)>2){ | |
| $char_datetime = array(); | |
| foreach($char_time as $char_char => $char_time_elem){ | |
| $char_datetime[$char_char] = new DateTime(); | |
| $char_time_elem = id2time($char_time_elem); | |
| $char_datetime[$char_char]->setTimestamp($char_time_elem/1000); | |
| $tweet .= $char_char . $char_datetime[$char_char]->format('m/d H:i:s.').sprintf("%03d",bcmod($char_time_elem,1000)).PHP_EOL; | |
| } | |
| $diff_kaso = time_diff($char_time['か'],$char_time['そ']); | |
| $diff_soku = time_diff($char_time['く'],$char_time['そ']); | |
| $diff_kaku= time_diff($char_time['か'],$char_time['く']); | |
| if($diff_kaso + $diff_soku == $diff_kaku){ | |
| $tweet .= 'ksk score:'.$diff_kaku.'ms'; | |
| }else{ | |
| $tweet .= 'failure'; | |
| } | |
| $tweet = '@'.$status->user->screen_name . PHP_EOL . $tweet; | |
| $res = $uo->post('statuses/update',array( | |
| 'status'=> $tweet, | |
| 'in_reply_to_status_id' => $status->id_str | |
| )); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment