Module: TrumpcareTracker::RakeTask::Methods

Included in:
TrumpcareTracker::Reporters, TweetBot
Defined in:
lib/trumpcare_tracker/rake_task.rb

Instance Method Summary collapse

Instance Method Details

#audit_rep(i, rep, &block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/trumpcare_tracker/rake_task.rb', line 31

def audit_rep(i, rep, &block)
  puts "Sending requests to Twitter API for #{rep.official_full}"
  alt_screen_name = handles.detect do |handle|
    handle['official'].downcase.strip == rep.twitter.downcase.strip
  end['personal/campaign']
  tracker = TrumpcareTracker.new(rep.official_full, rep.twitter, alt_screen_name)
  tracker.audit
  block.call(tracker, rep) if block_given?
  puts "#{i + 1} down. Pausing for 45 seconds to avoid hitting API rate limit."
  sleep(45)
rescue Twitter::Error::TooManyRequests
  puts 'Rate limit exceeded, waiting 5 minutes'
  sleep(300)
  audit_rep(i, rep, &block)
rescue Twitter::Error => e
  puts e.message
  audit_rep(i, rep, &block)
end

#audit_tweets(reps, &block) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/trumpcare_tracker/rake_task.rb', line 50

def audit_tweets(reps, &block)
  reps.each_with_index do |rep, i|
    next if rep.twitter.nil?
    audit_rep(i, rep, &block)
  end
ensure
  `say "beep beep beep beep beep"`
end

#handlesObject



27
28
29
# File 'lib/trumpcare_tracker/rake_task.rb', line 27

def handles
  @_handles ||= CSV.read(File.expand_path('../twitter_handles.csv', __FILE__), headers: true)
end

#mentions_mapper(doc, regex) ⇒ Object



59
60
61
# File 'lib/trumpcare_tracker/rake_task.rb', line 59

def mentions_mapper(doc, regex)
  doc.text.split("\n").select { |string| string.downcase.match?(regex) }
end

#repsObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/trumpcare_tracker/rake_task.rb', line 13

def reps
  democrats = PYR.reps do |r|
    r.democrat = true
    r.chamber  = 'upper'
  end

  independents = PYR.reps do |r|
    r.independent = true
    r.chamber     = 'upper'
  end

  democrats.objects.to_a + independents.objects.to_a
end