Skip to content

Instantly share code, notes, and snippets.

@akameco
Created May 13, 2014 07:15
Show Gist options
  • Save akameco/d7b05d0050b0abd016f5 to your computer and use it in GitHub Desktop.
Save akameco/d7b05d0050b0abd016f5 to your computer and use it in GitHub Desktop.
アップデートネーム
# coding: utf-8
require 'rubygems'
require 'twitter'
CONSUMER_KEY = 'APIキー'
CONSUMER_SECRET = 'APIシークレットキー'
ACCESS_TOKEN = 'アクセストークン'
ACCESS_TOKEN_SECRET = 'アクセストークンシークレット'
client = Twitter::REST::Client.new do |config|
config.consumer_key = CONSUMER_KEY
config.consumer_secret = CONSUMER_SECRET
config.access_token = ACCESS_TOKEN
config.access_token_secret = ACCESS_TOKEN_SECRET
end
stream_client = Twitter::Streaming::Client.new do |config|
config.consumer_key = CONSUMER_KEY
config.consumer_secret = CONSUMER_SECRET
config.access_token = ACCESS_TOKEN
config.access_token_secret = ACCESS_TOKEN_SECRET
end
stream_client.user do |status|
next unless status.is_a? Twitter::Tweet
next if status.text.start_with? "RT"
# @の後ろは自分のスクリーンネーぬに変更
if status.text =~ /.+?\(@akameco\)/
name = status.text.gsub("(@akameco)","")
next if name.length > 20
client.update_profile(:name => name)
option = {"in_reply_to_status_id" => status.id.to_s}
tweet = "@#{status.user.screen_name} #{name}にアップデートネームしました"
client.update tweet,option
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment