Skip to content

Instantly share code, notes, and snippets.

@clicube
Last active August 29, 2015 14:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clicube/573ce2f2d14b1acabf00 to your computer and use it in GitHub Desktop.
Save clicube/573ce2f2d14b1acabf00 to your computer and use it in GitHub Desktop.
require 'yaml'
require 'twitter'
#OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
CONFIG_FILE = File.dirname(__FILE__) + "/config.yaml"
config_data = YAML.load_file(CONFIG_FILE)
stream_client = Twitter::Streaming::Client.new do |config|
config.consumer_key = config_data['consumer_key']
config.consumer_secret = config_data['consumer_secret']
config.access_token = config_data['access_token']
config.access_token_secret = config_data['access_token_secret']
end
rest_client = Twitter::REST::Client.new do |config|
config.consumer_key = config_data['consumer_key']
config.consumer_secret = config_data['consumer_secret']
config.access_token = config_data['access_token']
config.access_token_secret = config_data['access_token_secret']
end
stream_client.user do |object|
next unless object.is_a?(Twitter::Tweet)
next unless object.in_reply_to_screen_name == "sort_rb"
text = object.text.dup
text.gsub!(/@[A-Za-z0-9_]+ /, "")
text.gsub!(/https?:\/\/[^ ]+/, "")
text = text.split(//).sort.join.strip
reply = "@#{object.user.screen_name} #{text}"
rest_client.update(reply, { in_reply_to_status: object })
end
consumer_key: xxxxxxxx
consumer_secret: xxxxxxxx
access_token: xxxxxxxx
access_token_secret: xxxxxxxx
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE

を不要にするためには、

# apt-get install ca-certificates

とする。(Windowsはわかりません)

consumer_key などは、 https://apps.twitter.com で確認。 (実際に使うアカウントでログインしよう)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment