[
板情報
|
カテゴリランキング
]
したらばTOP
■掲示板に戻る■
全部
1-100
最新50
|
1-
101-
この機能を使うにはJavaScriptを有効にしてください
|
botにこんな機能があったらいいなスレ
1
:
pha
:2009/12/17(木) 09:02:47
誰かのスクリプトで実装済みのものや、どこにも実装されてない思いつきでも、
なんでも思いついたら書いていってくださいー
99
:
名無しさん
:2011/08/05(金) 18:59:28
初心者スレにmentions,home_timeline重複取得に関して質問があったので、ちょっと書いておきます。
EB2はなぜか取得にscince_idパラメータを使用していません。重複削除には時間を使用しています。
(おそらくEB1で、ファイルを保存したりしないようにしようと考えたのでしょう。)
$limittime = $now - $minute * 70; //取りこぼしを防ぐために10秒多めにカウントしてる
しかもちょっと計算式違いますw $limittime = $now - ($minute * 60 + 10);でしょう
これに、GAE-cronのルーズさも加わって、おそらく正確には処理できていないと思われます。
$tweet_id = (string)$tweet->id;
if($limittime <= $time && $this->_latestReply < $tweet_id){ .....
「こいつバカじゃないの?↑の行で処理しているじゃん!」と思うかもしれませんが、
Snowflakeの導入でステータスIDは整数のintを超えていてfloat扱いになって以降、このへんかなり怪しいです。
詳しくは
http://ideone.com/LWSm3
参照
$this->_latestReplyの内容はlog.datに書きこまれた、最後にリプライしたステータスIDですが、
リプライ処理、TL処理の両方で兼用しているので、トレースすればわかるのですが、どっちの最後の値かわかりません。
両方終えた大きな方です。
mentions、home_timelineに同じ$this->_latestReplyを使うと、どちらかで取りこぼしの”可能性”が出てきます。
なので、修正内容は、
1.リプライ、TLで最後にリプライしたステータスIDを別々に保存する。
2.保存したステータスIDをscince_idパラメータにして、mentions、home_timelineを取得する。
の修正が必要になります。
100
:
名無しさん
:2011/08/05(金) 19:01:36
>>99
の続き
以下に具体的な変更”案”を提示します。あくまで”案”です。
文法チェックと脳内トレースしかしていないので、過不足あるかもしれませんが、
おそらくこんな感じの修正になると思います。
-------------------------------------------------------------
コンストラクタ
$this->_repliedReplies = array();
$this->_logDataFile = "log.dat";
$this->_latestReply = file_get_contents($this->_logDataFile);
の下に
$this->_TLrepliedReplies = array();
$this->_TLlogDataFile = "TLlog.dat";
$this->_TLlatestReply = file_get_contents($this->_TLlogDataFile);
を追加
TLlog.datは予めlog.datをコピーして書き込み可で作成しておく。
-------------------------------------------------------------
同じくコンストラクタ
//どこまでリプライしたかを覚えておく
function saveLog(){
rsort($this->_repliedReplies);
return file_put_contents($this->_logDataFile,$this->_repliedReplies[0]);
}
の下に
function saveLogTL(){
rsort($this->_TLrepliedReplies);
return file_put_contents($this->_TLlogDataFile,$this->_TLrepliedReplies[0]);
}
-------------------------------------------------------------
reply関数内
$response = $this->getRecentTweets($response, $cron * $replyLoopLimit * 3);
$replies = $this->getRecentTweets($response, $cron);
の2行削除
since_idを使うのでgetRecentTweets関数は不要になる
-------------------------------------------------------------
reply関数内
$replies = $this->selectTweets($replies);
を
$replies = $this->selectTweets($respons);
に変更
101
:
名無しさん
:2011/08/05(金) 19:02:07
>>100
の続き
-------------------------------------------------------------
replyTimeline関数内
$timeline = $this->getRecentTweets($timeline, $cron);
を削除
since_idを使うのでgetRecentTweets関数は不要になる
-------------------------------------------------------------
replyTimeline関数内
$this->_repliedReplies[] = (string)$response->in_reply_to_status_id;
を
$this->_TLrepliedReplies[] = (string)$response->in_reply_to_status_id;
に変更
-------------------------------------------------------------
replyTimeline関数内
if(!empty($this->_repliedReplies)){
$this->saveLog();
}
を
if(!empty($this->_TLrepliedReplies)){
$this->saveLogTL();
}
に変更
--------------------------------------------------
removeRepliedTweets関数内
$id = (string)$reply->id;
if(in_array($id, $this->_repliedReplies) === FALSE){
$replies[] = $reply;
}
を、値がfloatだとin_arrayがまともに動作しないっぽいので
$replied_flg = false;
foreach($this->_repliedReplies as $k => $v){
if ($id === $v){
$replied_flg = true;
break;
}
}
foreach($this->_TLrepliedReplies as $k => $v){
if ($id === $v){
$replied_flg = true;
break;
}
}
if ($replied_flg == false){
$replies[] = $reply;
}
に変更
--------------------------------------------
function getFriendsTimeline(){
$url = "
http://api.twitter.com/1/statuses/home_timeline.xml";
return $this->_getData($url);
}
を
function getFriendsTimeline(){
$url = "
http://api.twitter.com/1/statuses/home_timeline.xml";
$url .= "?since_id=".$this->_TLlatestReply;
$url .= "&include_rts=false";
$url .= "&exclude_replies=true";
return $this->_getData($url);
}
に変更
--------------------------------------------
function getReplies($page = false)
{
$url = "
http://api.twitter.com/1/statuses/mentions.xml";
if ($page) {
$url .= '?page=' . intval($page);
}
return $this->_getData($url);
}
を
function getReplies($page = false){
$url = "
http://api.twitter.com/1/statuses/mentions.xml";
$url .= "?since_id=".$this->_latestReply;
$url .= "&include_rts=false";
if ($page) {
$url .= '&page=' . intval($page);
}
return $this->_getData($url);
}
に変更
--------------------------------------------
私はあまりEB詳しくないので、この修正が必要か否かの判断も含め、後のことはEBユーザーさんに丸投げしようと思います。
新着レスの表示
名前:
E-mail
(省略可)
:
※書き込む際の注意事項は
こちら
※画像アップローダーは
こちら
(画像を表示できるのは「画像リンクのサムネイル表示」がオンの掲示板に限ります)
スマートフォン版
掲示板管理者へ連絡
無料レンタル掲示板