public
Description: my random ruby scripts
Homepage:
Clone URL: git://github.com/kastner/ruby-junk.git
Click here to lend your support to: ruby-junk and make a donation at www.pledgie.com !
ruby-junk / annoy-reply.rb
100755 46 lines (36 sloc) 0.997 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env ruby
require 'rubygems'
require 'open-uri'
require 'json'
require 'net/http'
 
TWITTER_USER = ""
TWITTER_PASS = ""
 
LAST_TWEET_FILE = ".last_tweet"
 
def last_tweet
  @last_tweet ||= open(LAST_TWEET_FILE).read rescue 0
end
 
def url
  "http://search.twitter.com/search.json?q=%s&since_id=#{last_tweet}"
end
 
def tweets_for_word(word)
  json = JSON.parse(open(url % word).read)
  json["results"]
end
 
def send_update(tweet)
  Net::HTTP.post_form(URI.parse("http://#{TWITTER_USER}:#{TWITTER_PASS}@twitter.com/statuses/update.json"),
    {'status' => tweet}
  )
end
 
def update_last_tweet(tweet_id)
  File.open(LAST_TWEET_FILE, "w") do |f|
    f.puts tweet_id
  end
end
 
co_working_tweets = tweets_for_word("co-working")
co_working_tweets.reverse.each do |tweet|
  next if tweet["id"] == last_tweet
  my_tweet = "@#{tweet["from_user"]} it's coworking"
  puts "Sending #{my_tweet}"
  # send_update(tweet)
end
 
# update_last_tweet(co_working_tweets.first["id"]) if co_working_tweets.first