Skip to content

Instantly share code, notes, and snippets.

@beccasaurus
Created September 30, 2010 04:26
Show Gist options
  • Save beccasaurus/604015 to your computer and use it in GitHub Desktop.
Save beccasaurus/604015 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'restclient'
require 'nokogiri'
require 'sequel'
DB = Sequel.sqlite 'course-stuff.sqlite'
html = RestClient.get 'https://webapp4.asu.edu/catalog/classlist?s=&t=2109&e=open&hon=F'
doc = Nokogiri::HTML(html)
unless DB.tables.include? :courses
DB.create_table :courses do
primary_key :id
String :name
String :location
String :days
end
end
if DB[:courses].count == 0
def clean_up str
str.strip.gsub(/\n/, '')
end
doc.css('.titleColumnValue').each do |td|
row = td.parent
course_name = clean_up row.css('.titleColumnValue').text.sub(/Topic: \s+/, 'Topic: ')
location_name = clean_up row.css('.locationBuildingColumnValue').text
day_list = clean_up row.css('.dayListColumnValue').text
puts "#{course_name} is at #{location_name} on days: #{ day_list }"
DB[:courses].insert :name => course_name, :location => location_name, :days => day_list
end
else
DB[:courses].each do |course|
puts course.inspect
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment