Skip to content

Instantly share code, notes, and snippets.

Created December 10, 2009 01:23
Show Gist options
  • Save anonymous/253023 to your computer and use it in GitHub Desktop.
Save anonymous/253023 to your computer and use it in GitHub Desktop.
require "hpricot" # need hpricot and open-uri
require "open-uri"
require "date"
current_date = Date.civil(2007, 6, 16)
while (current_date != Date.today)
puts current_date.to_s + ":" + fetch_number_of_assaults(current_date).to_s
current_date = current_date.next
end
def to_everyblock_format(some_date)
some_date.year.to_s + '-' + some_date.month.to_s + '-' + some_date.day.to_s
end
def fetch_number_of_assaults(current_date, extra_params = "")
date = to_everyblock_format(current_date)
doc = Hpricot(open("http://chicago.everyblock.com/crime/by-primary-type/assault/by-date/" + date.to_s + ',' + date.to_s + "/" + extra_params))
size = (doc/"li.newsitem").size
if (doc/"a.next").empty?
size
else
size + (fetch_number_of_assaults current_date, doc.at("a.next")['href'].to_s)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment