define("SELF", basename(__FILE__)); define("TITLE", "twbot2.rb - Twitter Bot Support Library in Ruby"); define("STYLE", "h1{font-family:serif} pre{background:white}"); require_once('../../hhiro.net/__base__.php'); if(EN) define("TOPURL", "http://hhiro.net/"); ?> lang_switch(); ?> begin_section("Download","en"); ?> begin_section("ダウンロード","ja"); ?>
twbot2.rb (new version)
twbot.rb (old version)
if(EN){ ?>* No longer accessible to Twitter (OAuth authentication is not used) }else{ ?>※現在はTwitterへのアクセス不可能(OAuthによる認証に未対応のため) } ?>twbot2.rb version 0.21 is released, working with hlink("https://dev.twitter.com/docs/api/1.1/overview","Twitter API v1.1");?>. APIs of twbot2.rb are refined, however, programs for library version 0.20 still works with library version 0.21. The document for version 0.21 is available at hlink("https://github.com/maraigue/twbot2.rb/wiki","GitHub wiki page");?>. (2013.2.5)
Since hlink("https://dev.twitter.com/pages/application-permission-model","direct message APIs will be unavailable with old OAuth tokens since July 2011");?>, please re-authenticate accounts if you use direct message APIs. To re-authenticate a user USERNAME, first remove 'users/USERNAME' entry (including 'token', 'secret' or like section under it) from config.yml, then execute 'ruby BOT_SCRIPT_NAME.rb add=USERNAME'. (2011.6.28)
twbot2.rb, the renewed version of twbot.rb, has released. As old twbot.rb does not support OAuth, hlink("http://groups.google.com/group/twitter-development-talk/browse_thread/thread/dfb89d9f29f339a2","It will not work from August 31st, 2010");?>. You can change the library from old twbot.rb to twbot2.rb with a little work. (2010.5.16)
}else{ ?>twbot2.rbのバージョン0.21をリリースしました。 hlink("https://dev.twitter.com/docs/api/1.1/overview","Twitter API v1.1");?>への対応済みです。またtwbot2.rbのAPIが更新されています(なお、バージョン0.20向けに書かれたプログラムはだいたいバージョン0.21でも動きます)。バージョン0.21向けドキュメントは hlink("https://github.com/maraigue/twbot2.rb/wiki","GitHub wiki page");?>をご覧ください(現在は英語のみ)。 (2013.2.5)
hlink("http://www.greenspace.info/mt/2011/05/19/twitter_api_dm.html","2011年7月より、ダイレクトメッセージ関連のAPIが、古いOAuthトークンでは利用不可能になります");?>。利用されたい場合は、再度認証をお願いします。なお再度認証を行うには、まずconfig.ymlファイルから'users/USERNAME'のエントリ(直下の'token'や'secret'も含む)を削除し、その後'ruby BOT_SCRIPT_NAME.rb add=USERNAME'を実行します。(2011.6.28)
twbot.rbの新しいバージョン「twbot2.rb」を公開開始しました。古いtwbot.rbはOAuthに対応しておらず、 hlink("http://japan.cnet.com/news/service/story/0,3800104747,20415441,00.htm","8月31日以降は利用出来なくなります");?>のでご注意下さい。なお、twbot.rbからtwbot2.rbへの移行は少ない労力で行えるようになっております。(2010.5.16)
} ?> end_section(); ?> begin_section("Overview","en"); ?> begin_section("概略","ja"); ?> if(EN){ ?>twbot2.rb is a library for hlink("http://www.ruby-lang.org/","Ruby programming language");?>, which supports making hlink("http://www.ruby-lang.org/","Twitter");?> bots: mainly managing OAuth tokens. This program might be said a framework.
}else{ ?>twbot2.rbは、 hlink("http://www.ruby-lang.org/","Ruby");?>にて hlink("http://www.ruby-lang.org/","Twitter");?>のbot(プログラムにより自動的に発言を行うアカウント)作成を行う際に、その補助を行う(主に、OAuthトークンの管理を行う)ライブラリです。どちらかといえばフレームワークに近いかもしれません。
} ?> if(EN){ ?>twbot.rb especially help you make Twitter bots that get data periodically from certain place (RSS, Twitter timeline, etc.) and create updates from that data.
}else{ ?>特に、定期的に特定の位置からデータを取得し(RSSやTwitterのタイムラインなど)、それに基づいて発言を行うbotを作るのに適したものとなっています。
} ?> end_section(); ?> begin_section("Requirements","en"); ?> begin_section("必要な環境","ja"); ?> if(EN){ ?>A PC for executing program repeatedly with hlink("http://www.ruby-lang.org/","Ruby");?> interpreter
}else{ ?>hlink("http://www.ruby-lang.org/","Ruby");?>インタプリタの導入されている、定期的にプログラムを実行させるためのPC
} ?>A bot tweeting random greetings
}else{ ?>あいさつをランダムに発言するbot
} ?>require "./twbot2" TwBot.create("config-file.yml", "log-file.log").cui_menu do # if(EN){ ?>Define what the bot tweets here }else{ ?>ここに話す内容を定義する } ?> tweet_list = ["Good morning", "Good afternoon", "Good evening"] [tweet_list[rand(tweet_list.size)]] # if(EN){ ?>return as an array }else{ ?>返り値は配列 } ?> endif(EN){ ?>
A bot tweeting RSS contents
}else{ ?>RSSの内容を発言するbot
} ?>#!/usr/bin/env ruby # -*- coding: utf-8 -*- RSS_URL = "http://d.hatena.ne.jp/maraigue/rss" require "cgi" require "open-uri" require "./twbot2" SELFDIR = File.dirname(__FILE__) TwBot.create("#{SELFDIR}/config-rsspost.yml", "#{SELFDIR}/error-rsspost.log").cui_menu do # Download RSS buf = nil open(RSS_URL){ |file| buf = file.read } result = [] @config["already_retrieved"] ||= "" newest_entry = false # Retrieve entries in RSS # (It is better to use REXML library; this program omits it # for simpleness.)] buf.scan(/<item.*?>.*?<\/item>/m).each do |entry| # Extract titles and URLs of entries from downloaded RSS title = nil entry.scan(/<title>(.*?)<\/title>/){|tmp| title = CGI.escapeHTML(tmp[0])} link = nil entry.scan(/<link>(.*?)<\/link>/){|tmp| link = CGI.escapeHTML(tmp[0])} # Ignore entries already retrieved by this program # # NOTE: @config["..."] values are kept for the next running # of the program. break if link == @config["already_retrieved"] # Adds a message to the list to be tweeted later. # # Because RSS stores entries from newer one, to post messages in the # original order, the message have to be added to the bottom of the # array 'result'. result.unshift(TwBot."[AUTO POST] #{link} #{title}") if title && link # Keep the URL of the newest entry in the data retrieved now unless newest_entry newest_entry = true @config["already_retrieved"] = link end end # Set logged message @logmsg = "(#{result.size} post added)" # Return the result # # NOTE: the returned value must be an array of tweets when a bot # is constructed (called by 'ruby SCRIPTNAME.rb load') result endif(EN){ ?> More details: maraigue/twbot2.rb · GitHub }else{ ?> 詳細(英語): maraigue/twbot2.rb · GitHub } ?> end_section(); ?> begin_section("Reference","en"); ?> begin_section("詳細リファレンス","ja"); ?>
hlink("https://github.com/maraigue/twbot2.rb/wiki", "Help for twbot2.rb version 0.21 or newer");?> (English)
OLD VERSIONS:
TwBot#get_followers
, TwBot#get_friends
, TwBot#follow
, TwBot#unfollow
, TwBot#following_status
, TwBot.retrieve_followers
, TwBot.retrieve_friends
, TwBot.make_following
, TwBot.make_unfollowing
, TwBot.check_following
)TwBot#get_followers
, TwBot#get_friends
, TwBot#follow
, TwBot#unfollow
, TwBot#following_status
, TwBot.retrieve_followers
, TwBot.retrieve_friends
, TwBot.make_following
, TwBot.make_unfollowing
, TwBot.check_following
)を追加した。(C)2008- H.Hiro(Maraigue)
if(EN){ ?>twbot.rb can be copied and changed under (new) BSD License. BSD License
Simply, this script is distributed under no warranty, and re-distributed version have to contain original copyright information.
To report about this script, talk to Twitter/h_hiro, or send mail to main (AT) hhiro.net .
}else{ ?>twbot.rbの複製・改変の条件は、(新)BSDライセンスに合わせます。BSDライセンス(原文) BSDライセンス(参考訳)
簡単に言えば、このソフトは無保証であり、また再配布(改変した上での再配布含む)の場合にも元の著作権表示などの部分が記されている必要があります。
私が使いやすいように書いているため、使いにくい点があるかもしれません。あらかじめご了承下さい。要望は可能な限りお受けします。
スクリプトに関する報告は、Twitter/h_hiro_および、メールアドレスmain(あっとまーく)hhiro.netにお願いします。
} ?> end_section(); ?> if(!EN){ ?>hlink("../","Maraigue's roomに戻る");?>
} ?> footer(); ?>