Skip to content

Instantly share code, notes, and snippets.

@rummelonp
Created May 12, 2012 10:12
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 rummelonp/2665644 to your computer and use it in GitHub Desktop.
Save rummelonp/2665644 to your computer and use it in GitHub Desktop.
Creepy 用のタスク
# -*- coding: utf-8 -*-
module Creepy
module Tasks
class Fav < Base
Tasks.add_task :fav, self
desc '(´へεへ`*)'
def self.banner
"#{super} [screen_name]"
end
MAX_COUNT = 200
argument :screen_name
class_option :count, :aliases => '-c', type: :numeric, default: MAX_COUNT
class_option :interval, :aliases => '-i', type: :numeric, default: 0
def setup
shell.say "Fav#setup: @#{screen_name}"
@client = Creepy.client
page = 1
@tweets = []
loop do
begin
@tweets.concat(@client.user_timeline(screen_name, :count => MAX_COUNT, :page => page))
@tweets = @tweets.uniq.select {|t| ! t.favorited}
page += 1
break if @tweets.size >= options[:count]
rescue
shell.error "Fav#setup: #{$!.message} (#{$!.class})"
retry
end
end
@tweets = @tweets.slice(0, options[:count])
end
def fav
@tweets.each_with_index do |tweet, index|
shell.say "Fav#fav: #{index}: #{tweet.text}"
Thread.new do
sleep index * options.interval
begin
@client.favorite(tweet.id)
shell.say "Fav#fav: #{index}: favorite"
rescue
shell.error "Fav#fav: #{index}: #{$!.message} (#{$!.class})"
end
end
end
end
def teardown
Thread::list.each do |t|
t.join if t != Thread::current
end
end
end
end
end
# -*- coding: utf-8 -*-
module Creepy
module Tasks
class Remtter < Base
Tasks.add_task :remtter, self
desc 'Monitoring the followers'
def self.banner
"#{super} [screen_name]"
end
argument :screen_name
def setup
shell.say "Remtter#setup: @#{screen_name}"
@db = Creepy.db
@col = @db['remtter']
@client = Creepy.client
@doc = @col.find_one({'screen_name' => screen_name})
@current = @client.follower_ids(screen_name).ids
@before = @doc ? @doc['ids'] : @current
end
def analytics
@follow = (@current - @before).map {|id| name(id)}.reject(&:nil?)
@unfollow = (@before - @current).map {|id| name(id)}.reject(&:nil?)
end
def send_messages
until @follow.empty?
message = "Followed by: #{@follow.slice!(0, 7).join(' ')}"
shell.say "Remtter#send_messages: #{message}"
d(message)
end
until @unfollow.empty?
message = "Unfollowed by: #{@unfollow.slice!(0, 7).join(' ')}"
shell.say "Remtter#send_messages: #{message}"
d(message)
end
end
def save
if @doc
@doc['ids'] = @current
else
@doc = {'screen_name' => screen_name, 'ids' => @current}
end
@col.save @doc
end
private
def name(id)
name = @client.user(id).screen_name
"@#{name}"
rescue
shell.error "Remtter#name: user id \"#{id}\": #{$!.message} (#{$!.class})"
end
def d(message)
@client.direct_message_create screen_name, message
rescue
shell.error "Remtter#d: #{$!.message} (#{$!.class})"
end
end
end
end
# -*- coding: utf-8 -*-
module Creepy
module Tasks
class Xfollow < Base
Tasks.add_task :xfollow, self
desc '=͟͟͞͞( ∩ω∩ ) _`’;.;(,`(. 、,)*)”.:\';"_ ボンッ'
def self.banner
"#{super} [screen_name, ...]"
end
argument :screen_names
class_option :exclude, :aliases => '-e', :type => :string, :default => '',
:desc => 'Exclude friends screen_name separated by a comma.'
class_option :threshold, :aliases => '-t', :type => :numeric, :default => 2,
:desc => 'Followers count threshold.'
class_option :protected, :aliases => '-p', :type => :boolean, :default => false,
:desc => 'Exclude protected followings.'
def setup
@client = Creepy.client
@friends = screen_names.split(',')
@exclude = options.exclude.split(',')
@friends_data = friends_data(@friends)
@exclude_ids = friends_data(@exclude).values.flatten.uniq
end
def analytics
@analyzed_data = @friends_data.inject({}) {|data, (name, ids)|
ids.each do |id|
data[id] = {:count => 0, :users => []} unless data.key? id
data[id][:count] += 1
data[id][:users] << name
end
data
}.select {|id, data|
data[:count] >= options.threshold && !@exclude_ids.include?(id)
}.sort_by {|id, data|
- data[:count]
}
end
def show
@analyzed_data.each do |id, data|
begin
user = @client.user(id)
next if user.protected && options.protected
shell.say "XFollow#show: @#{user.screen_name}: #{data[:users].join(' ')}"
rescue
shell.error "XFollow#show: #{id}: #{$!.message} (#{$!.class})"
end
end
end
private
def friends_data(users)
data = {}
users.each do |user|
begin
ids = @client.friend_ids(user).ids
data[user.to_sym] = ids
shell.say "XFollow#friends_data: @#{user}: #{ids.size} friends"
rescue
shell.error "XFollow#friends_data: @#{user}: #{$!.message} (#{$!.class})"
end
end
data
end
end
end
end
# -*- coding: utf-8 -*-
module Creepy
module Tasks
class C顔 < Base
Tasks.add_task :顔, self
TEXT = 'a-zA-Z0-9ぁ-ヶ亜-黑a-zA-Z'
TEXT_PATTERN = /[#{TEXT}]/
NOT_TEXT_PATTERN = /[^#{TEXT}]/
FACE_PATTERN = /(#{NOT_TEXT_PATTERN}*[\((](?:(?!#{TEXT_PATTERN}{3,}).){2,}[\))]#{NOT_TEXT_PATTERN}*)/
def setup
@db = Creepy.db
@col = @db['status']
@sel = {'text' => {'$regex' => FACE_PATTERN}}
end
def 顔
data = []
@col.find(@sel).each do |status|
text = status['text'].match(FACE_PATTERN).to_s
if text.present? && !data.include?(text)
data << text
shell.say text
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment