Created
December 10, 2009 01:23
-
-
Save anonymous/253023 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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