Skip to content

Instantly share code, notes, and snippets.

@ultraist
Created January 24, 2012 12:28
Show Gist options
  • Save ultraist/1669991 to your computer and use it in GitHub Desktop.
Save ultraist/1669991 to your computer and use it in GitHub Desktop.
キモトAPI判定bot @kimoto_fan
# -*- coding: utf-8 -*-
require 'rubygems'
require 'twitter'
require 'gdbm'
require 'json'
require 'tweetstream'
# configure
OAUTH_CONFIG = Proc.new do |config|
config.consumer_key = ""
config.consumer_secret = ""
config.oauth_token = ""
config.oauth_token_secret = ""
end
DIR_NAME = File.expand_path(File.dirname(__FILE__))
DB_FILE = File.join(DIR_NAME, "id.dbm")
BAITAI_ID = 3523861 # bulkneets
# gogo kimolog
Twitter.configure do |config|
OAUTH_CONFIG.call(config)
end
TweetStream.configure do |config|
config.auth_method = :oauth
OAUTH_CONFIG.call(config)
end
def randomize(s, tweet)
case rand(2)
when 0
c = rand(41) + 1
"↓" * c + " " + s + " " + "↓" * c
when 1
new_s = ""
s.chars.each do |c|
new_s << c * (rand(10) + 1)
end
"↓ " + new_s + " ↓"
end
end
def make_tweet(tweet)
kimoto = %w(
キモト
キモッサン
)
randomize(kimoto.sample(1).first, tweet)
end
def update(client, tweet)
client.update(make_tweet(tweet))
# p make_tweet(tweet)
end
GDBM.open(DB_FILE) do |dbm|
client = Twitter::Client.new
ts = TweetStream::Client.new
ts.follow(BAITAI_ID) do |tweet|
if (tweet.user.id_str == BAITAI_ID.to_s &&
!tweet.retweeted)
id = tweet.id.to_s
unless (dbm[id])
dbm[id] = tweet.to_json
if (tweet.source =~ /キモトタクミ/)
begin
update(client, tweet)
rescue => e
p e
p e.backtrace
end
end
end
end
end
end
require 'rubygems'
require 'daemons'
require 'fileutils'
DIR_NAME = File.expand_path(File.dirname(__FILE__))
KIMOLOG = File.join(DIR_NAME, "kimolog.rb")
LOG_DIR = File.join(DIR_NAME, "./log")
unless (File.directory?(LOG_DIR))
FileUtils.mkdir_p(LOG_DIR)
end
Daemons.run(
KIMOLOG,
:app_name => File.basename(KIMOLOG),
:dir_mode => :normal,
:dir => LOG_DIR,
:keep_pid_files => true,
:backtrace => true
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment