Skip to content

Instantly share code, notes, and snippets.

@tobynet
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobynet/9061907 to your computer and use it in GitHub Desktop.
Save tobynet/9061907 to your computer and use it in GitHub Desktop.
コマンドラインから選んで即FavしたりRTするやつ (tw gem でとってきたタイムラインを percol で選択して、 tw gem でFavったりRTする)
#!/usr/bin/env bash
# # Requirements:
#
# * percol : https://github.com/mooz/percol
# * tw gem : http://shokai.github.io/tw/
#set -o xtrace # for debug output. ( abbr. set -x )
set -o errexit # for exit on error. ( abbr. set -e )
set -o pipefail # errexit for pipe
set -o nounset # exit when the script to use undeclared variables (abbr. set -u)
TW_USER=${TW_USER:+--user=$TW_USER}
TW_QUERY=--search=+ジャバ
TW_OPTIONS=(--id --reverse)
ACTION=--fav=
# Show usages
usage() {
set +o xtrace
cat <<EOD
The Fav Machine for CLI
Usage: $(basename $0) [OPTIONS] [QUERY]
-h, --help Show help
-f, --fav Fav mode (DEFAULT)
-r, --rt RT mode for retweeting instead of favorite
Examples:
# Show @_java_life's timeline and Fav selected tweets
$ $(basename $0) @_java_life
# Show @toby_net's list and Fav selected tweets
$ $(basename $0) @toby_net/java
# RT mode
$ $(basename $0) --rt
# Search ジャバ and Retweet selected tweets
$ $(basename $0) --rt --search=+ジャバ
# Select user of tw gem
$ $(basename $0) --user test_account
Hints:
* You can press CTRL-SPACE to select multiple tweets.
* WARNING: This tool has no confirmation UI.
EOD
}
# # If no argument, then print usage
# if [ $# = 0 ]; then
# usage
# exit 1
# fi
# Parse options
while [ $# -gt 0 ]; do
case "$1" in
-h | --help | -help )
usage
exit ;;
-r | --rt )
ACTION=--rt=
shift ;;
-f | --fav )
ACTION=--fav=
shift ;;
-u | --user )
shift
TW_USER=--user=$1
shift ;;
* )
break ;;
esac
done
TW_QUERY=${1:-"$TW_QUERY"}
tw "$TW_USER" "$TW_QUERY" "${TW_OPTIONS[@]}" --format=json 2> /dev/null \
| ruby -rjson -rdate -ne \
'j=JSON.parse($_); \
puts %(#{DateTime.parse(j["time"]).strftime("%Y-%m-%d %H:%M")} #{j["user"]}:\t#{j["text"].gsub(/\n/, "↲ ")} Fav:#{j["fav_count"]} RT:#{j["rt_count"]} - #{j["id"]})' \
| percol --reverse \
| sed -e 's/^.*- \([0-9]\+\)$/\1/g' \
| xargs -n 1 -t -I {} tw "$TW_USER" --yes "$ACTION{}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment