Skip to content

Instantly share code, notes, and snippets.

@authorNari
Created March 27, 2011 02:57
Show Gist options
  • Save authorNari/888870 to your computer and use it in GitHub Desktop.
Save authorNari/888870 to your computer and use it in GitHub Desktop.
my twitter!!!
# -*- coding: utf-8 -*-
$screen_names_of_me ||= []
$screen_names_of_timeline ||= []
$words_of_timeline ||= []
$tweet_counts ||= {}
$tweet_limit_of_day = 2
Earthquake.init do
output do |item|
next unless item["event"]
case item["event"]
when "favorite"
m = "[fav] #{item["source"]["screen_name"]}: #{item["target_object"]["text"]}"
notify m
else
true
end
end
output_filter do |item|
if item["_stream"]
filtering_item_on_stream?(item)
else
true
end
end
# limitation tweet by little and little
commands.delete_if{|m| m[:pattern] == %r|^[^:].*|}
command %r|^[^:].*| do |m|
today = Time.new.strftime("%Y%m%d")
$tweet_counts[today] ||= 0
next_tweet_count = $tweet_counts[today] + 1
over = next_tweet_count - $tweet_limit_of_day
cancel = false
if over > 0
c = ""
over.times do
cancel = !confirm("Today\'s tweet: #{$tweet_counts[today]}. Do you tweet?#{c}")
break if cancel
c += " Really?"
end
end
if cancel
puts "OK! Keep it up!!!"
break
end
cancel = !confirm("update '#{m[0]}'")
if !cancel
async { twitter.update(m[0]) }
$tweet_counts[today] = next_tweet_count
end
end
end
def filtering_item_on_stream?(item)
return true if item["text"].nil? || item["user"].nil? || item["entities"].nil? || item["entities"]["user_mentions"].nil?
$screen_names_of_me.each do |n|
if item["entities"]["user_mentions"].map{|m| m["screen_name"]}.compact.include?(n)
notify "#{item['user']['screen_name']}: #{item['text']}"
return true
end
end
return true if $screen_names_of_me.include?(item["user"]["screen_name"])
return true if $screen_names_of_timeline.include?(item["user"]["screen_name"])
return true if $words_of_timeline.any?{|w| item["text"].match(w) }
return false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment