-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.rb
29 lines (24 loc) · 866 Bytes
/
application.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
require './environment'
# This is the scraper portion of the application. This is meant to be run regularly
# by a cron job.
# Download the page that lists all of the per-Precinct reports.
home = Net::HTTP.get(URI('http://www.nyc.gov/html/nypd/html/crime_prevention/crime_statistics.shtml'))
doc = Nokogiri::HTML(home)
main = doc.css('#main_content')
# Find all of the links...
main.first.css('a').each do |link|
# ...and grab the ones that link to crime stats pdfs.
if link['href'].match /crime_statistics\/(.*.pdf)/
name = $1
url = "http://www.nyc.gov/html/nypd/downloads/pdf/crime_statistics/#{name}"
puts "Found URL: #{url}"
report = Report.new(url)
if report.save
puts "Saved a new report to #{report.public_url}"
else
puts 'There were problems saving the report.'
p report
end
end
end
puts 'All done.'