-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_via_search.rb
34 lines (25 loc) · 1.01 KB
/
update_via_search.rb
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
require './config/boot.rb'
require 'twitter'
puts "Updating the 'nought"
client = Twitter::REST::Client.new do |config|
config.consumer_key = ENV["consumer_key"]
config.consumer_secret = ENV["consumer_secret"]
config.access_token = ENV["access_token"]
config.access_token_secret = ENV["access_token_secret"]
end
original_count = DB[:tweets].count
since_id = DB[:tweets].max(:id).to_i
ts = Time.now
new_tweets = client.search("from:greg_doucette", result_type: "recent", since_id: since_id + 1).collect.to_a.reverse
te = Time.now
puts "Fetched #{new_tweets.count} tweets in #{te - ts}s"
p [since_id]
new_tweets.each do |t|
p [t.id, t.in_reply_to_status_id, t.created_at, t.text]
next if (DB[:tweets].where(id: t.id.to_s).count > 0)
if t.in_reply_to_status_id && (DB[:tweets].where(id: t.in_reply_to_status_id.to_s).count > 0)
DB[:tweets] << {id: t.id.to_s, created_at: t.created_at, tweet: t.to_h.to_json }
end
end
new_count = DB[:tweets].count
puts "#{original_count} -> #{new_count}"