Class: Turl::Collect

Inherits:
Object
  • Object
show all
Defined in:
lib/turl/collect.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run(argv) ⇒ Object



3
4
5
6
# File 'lib/turl/collect.rb', line 3

def self.run(argv)
  Turl.prepare_database!
  self.new.run(argv)
end

Instance Method Details

#fetch_and_save(since_id:) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/turl/collect.rb', line 17

def fetch_and_save(since_id:)
  Turl.logger.info "start Turl::Collect#fetch_and_save(since_id: #{since_id.inspect})"

  tweets = client.home_timeline(count: 200)
  tweets.each do |tweet_resp|
    next if tweet_resp.urls.empty?

    tweet = Tweet.from_response!(tweet_resp)

    tweet_resp.urls.each do |url|
      next if Link.ignored?(url)

      Link.from_response!(url, tweet)
    end
  end
  Turl.logger.info "done Turl::Collect#fetch_and_save(since_id: #{since_id.inspect})"
  tweets.first&.id
end

#run(argv) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/turl/collect.rb', line 8

def run(argv)
  since_id = nil
  loop do
    new_since_id = fetch_and_save(since_id: since_id)
    since_id = new_since_id if new_since_id
    sleep 60
  end
end