Skeptonomics
sorting social science fact from fiction

Ted Cruz ACA poll results:

Published by Skeptikos on Apr 3, 2014

Ted Cruz took a poll on facebook:

It didn't seem to go as planned. One article says it “blew up in his face”. I wrote a program to gather the results for him.

Yes: 1621 - 39%
No: 2515 - 61%

The earlier comments, which are easily visible on facebook, are heavily biased in favor of "yes". Thus the media response. But overall the "noes" get the majority, as you'd expect on a conservative facebook page.

Many people didn't follow instructions, so the numbers aren't perfect. (For example, one person wrote “No doubt at all I'm better off,” which was counted as a “no”.) 230 comments weren't included due to facebook weirdness.

Here's the ruby code, if you're curious:

=begin
A program for estimating the results of Ted Cruz's facebook poll.
=end

# login email and password
email = '[email here]'
pass = '[password here]'

require 'mechanize'
url = 'https://m.facebook.com/story.php?story_fbid=517779935000978&id=315496455229328&p=0'
agent = Mechanize.new

# hiding my Mechanize identity
agent.user_agent_alias = 'Linux Mozilla'

# logging in to facebook
login = agent.get('https://www.facebook.com/')
form = login.forms[0]
form.fields[1].value = email
form.fields[2].value = pass
form.submit
cruz = agent.get(url)
yes = 0
no = 0
failed = 0
# main loop
x = 0
begin
  if x != 0
    cruz = cruz.links.last.click
  end
  begin
    cruz.search("div[class='msg']").last.children.each do |post|
      if post.text[0..2].downcase == 'yes'
        yes += 1
      elsif post.text[0..1].downcase == 'no'
        no += 1
      end
    end
  rescue
    failed += 1
    puts 'page failed'
  end
  if x%10 == 0
    puts ''
    puts "#{x.to_s} pages done."
    puts "Failed: #{failed.to_s}"
    puts "Yes: #{yes.to_s}"
    puts "No: #{no.to_s}"
  end
  x += 1
end until cruz.links.last.text != "View next comments"
puts ''
puts ''
puts 'All done.'
puts ''
puts "Yes: #{yes.to_s}"
puts "No: #{no.to_s}"
puts "Failed: #{failed.to_s}"