twty とは
twty とは、mattn さんが作られたこちらのソフトです。コマンドライン で Twitter の各種操作が行なえます。
インストール
Go の環境が整っていれば、$ go get
でインストールできます。
$ go get github.com/mattn/twty
使い方(アカウント認証)
最初に使うときにはアカウント認証が必要です。$ twty
と実行すれば Webブラウザ が開き、ユーザ認証が成功すると PIN が取得できます。
このとき、ターミナルは以下のような表示になっています。
$ twty Open this URL and enter PIN. https://api.twitter.com/oauth/authenticate?oauth_token=HOGEHOGE PIN: 1234567 AAAAAA: ねこ BBBBBB: ねこ CCCCCC: ねこ DDDDDD: RT @yochii7: ワンフェス展示のメイドインアビスすげー
使い方(コマンド)
認証が終われば、各種コマンドが実行できます。実行できるコマンドは $ twty -h
で一覧表示できます。Twitter の REST API が提供している機能のいくつかがラップされています。実装されている機能を用いれば、だいたいの日常的な操作は可能かと思います。
$ twty -h Usage of twty: -a PROFILE: switch profile to load configuration file. -f ID: specify favorite ID -i ID: specify in-reply ID, if not specify text, it will be RT. -l USER/LIST: show list's timeline (ex: mattn_jp/subtech) -m FILE: upload media -u USER: show user's timeline -s WORD: search timeline -json: as JSON -r: show replies -v: detail display -ff FILENAME: post utf-8 string from a file("-" means STDIN) -count NUMBER: show NUMBER tweets at timeline. -since DATE: show tweets created after the DATE (ex. 2017-05-01) -until DATE: show tweets created before the DATE (ex. 2017-05-31) -since_id NUMBER: show tweets that have ids greater than NUMBER. -max_id NUMBER: show tweets that have ids lower than NUMBER.
例えば、特定のリストの内容を表示させたい場合は以下のようなコマンドを実行します。
$ twty -l hogehoge/list_no_meishou
JSON での出力も可能
-json
オプションを付与することで出力形式を JSON にすることができます。出力データを再利用する際に便利だと思います*1。
$ twty -json -l hogehoge/list_no_meishou
*1:定期的に cron で回し、得られたデータを DB に入れるなどの用途の際