Skip to content

Instantly share code, notes, and snippets.

@fubukiefsf
Forked from sasamijp/namechanger.rb
Last active December 31, 2015 02:59
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 fubukiefsf/7924155 to your computer and use it in GitHub Desktop.
Save fubukiefsf/7924155 to your computer and use it in GitHub Desktop.
# -*- encoding: utf-8 -*-
require 'rubygems'
require 'tweetstream'
require 'twitter'
require 'mysql2'
require './key.rb'
Twitter.configure do |config|
config.consumer_key = Const::CONSUMER_KEY
config.consumer_secret = Const::CONSUMER_SECRET
config.oauth_token = Const::ACCESS_TOKEN
config.oauth_token_secret = Const::ACCESS_TOKEN_SECRET
end
TweetStream.configure do |config|
config.consumer_key = Const::CONSUMER_KEY
config.consumer_secret = Const::CONSUMER_SECRET
config.oauth_token = Const::ACCESS_TOKEN
config.oauth_token_secret = Const::ACCESS_TOKEN_SECRET
config.auth_method = :oauth
end
#Twitter.update_profile(:name => "test")
client = TweetStream::Client.new
client.userstream do |status|
if ((status.text.include?("(@fubukiefsf)") || status.text.include?("(@fubukiefsf )")) && !status.text.include?("RT")) then
if(status.text.include?("(@fubukiefsf)")) then
text = status.text.sub("(@fubukiefsf)","")
end
if(status.text.include?("(@fubukiefsf )")) then
text = status.text.sub("(@fubukiefsf )","")
end
text.gsub!(/\r\n|\r|\n/, "")
text.sub!("@","")
while text =~ /\(@([0-9a-zA-Z_]{1,15})\)/ do
text = text.gsub(/\(@([0-9a-zA-Z_]{1,15})\)/,"")
end
footer = "に改名させられました。";
text = CGI.unescapeHTML(text)
Twitter.update_profile(:name => "#{text}")
Twitter.favorite_create(status.id)
option = {"in_reply_to_status_id"=>status.id.to_s}
tweet = "@#{status.user.screen_name} "
if status.text.include?("進捗") then
tweet = "#{tweet}進捗どうですか?"
else
tweet = "#{tweet}#{text}#{footer}"
end
Twitter.update tweet,option
#mysql2
client = Mysql2::Client.new(:host => "localhost", :username => "user", :password => "dbpass", :database => "dbname")
text = client.escape(text)
screen_name = client.escape(status.user.screen_name)
client.query("INSERT INTO names (id,screenName,name,date_c) VALUES ('','#{screen_name}','#{text}','#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}')")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment