Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed email issues, mayhaps?

  • Loading branch information...
commit 3e56bed1256a426f0e0d136c385cd2fe11c97ade 1 parent 0aa9169
@sczizzo authored
View
4 Gemfile
@@ -4,14 +4,13 @@ gem 'rails'
gem 'god'
gem 'foreman'
gem 'resque', :require => 'resque/server'
-# gem 'resque-scheduler'
+gem 'resque-scheduler'
gem 'whenever', :require => false
gem 'high_voltage'
gem 'nokogiri'
gem 'devise'
gem 'cancan'
gem 'omniauth'
-# gem 'koala'
group :assets do
gem 'haml'
@@ -26,7 +25,6 @@ end
group :development, :test do
gem 'sqlite3'
- # gem 'ruby-debug19', :require => 'ruby-debug'
end
group :test do
View
7 Gemfile.lock
@@ -141,6 +141,12 @@ GEM
redis-namespace (~> 1.0.2)
sinatra (>= 0.9.2)
vegas (~> 0.1.2)
+ resque-scheduler (1.9.9)
+ redis (>= 2.0.1)
+ resque (>= 1.8.0)
+ rufus-scheduler
+ rufus-scheduler (2.0.16)
+ tzinfo (>= 0.3.23)
sass (3.1.15)
sinatra (1.3.2)
rack (~> 1.3, >= 1.3.6)
@@ -191,6 +197,7 @@ DEPENDENCIES
pg
rails
resque
+ resque-scheduler
sass-rails!
sqlite3
turn
View
41 app/models/course.rb
@@ -33,9 +33,9 @@ def self.look_up_all
# Handles caching the call to look up course information
# Note: Safe to call repeatedly (unless skip_cache), but you probably shouldn't
- def look_up skip_cache=false
+ def look_up skip_cache=true#false
if skip_cache or spied_at.nil? or spied_at < 5.minutes.ago
- unless scrape_classes_website
+ unless scrape_classes_website # i.e. unless the course was updated
# Well, at least we tried
update_attributes({
:spied_at => Time.now,
@@ -47,21 +47,27 @@ def look_up skip_cache=false
# Notify certain spies immediately, or all attached spies when necessary
# Note: Do not call repeatedly, will send out duplicate messages
- def notify_all spies=nil
- if spies or last_status != status
+ def notify_all spy_ids=nil
+ if last_status != status or spy_ids != nil
+ if spy_ids
+ spies_to_notify = Spy.find spy_ids
+ else
+ spies_to_notify = spies
+ end
+
case status
# Will never be unspied
when 'no record found'
- notify spies, :course_not_found
+ notify spies_to_notify, :course_not_found
when 'consent required'
- notify spies, :consent_required
+ notify spies_to_notify, :consent_required
when 'no limit'
- notify spies, :no_limit
+ notify spies_to_notify, :no_limit
when 'open'
- notify spies, :opening_found
+ notify spies_to_notify, :opening_found
when 'closed'
if last_status.nil?
- notify spies, :course_found
+ notify spies_to_notify, :course_found
end
end
end
@@ -69,16 +75,15 @@ def notify_all spies=nil
# Send a message to a spy or list of spies
# Note: Do not call repeatedly, will send out duplicate messages
- def notify spies, mailer_method_name
- spies ||= self.spies
- spies = spies.respond_to?(:each) ? spies : [spies]
- spies.each do |spy|
+ def notify spies_to_notify, mailer_method_name
+ puts "**************\n\n\nNotifying\n\n\n***********************"
+ spies_to_notify ||= self.spies
+ spies_to_notify = [spies_to_notify] unless spies_to_notify.respond_to?(:each)
+ spies_to_notify.each do |spy|
SpyMailer.send(mailer_method_name, spy).deliver
end
end
-# private
-
# Heart of the data aquisition operation:
# Fortunately, the course website (classes.uchicago.edu) exposes a search
# function (search.php) and a course lookup function (courseDetail.php). This
@@ -89,8 +94,6 @@ def scrape_classes_website
# By NOT including the number argument, we do a lookup for the whole department
# In the end, this is much more efficient for both Classes and ScheduleSpy
- #
- # course_url = "https://classes.uchicago.edu/search.php?Keyword=#{department}%20#{number}&CourseLevel=Undergraduate&TermName=#{CURRENT_QUARTER_NAME}+#{CURRENT_YEAR}"
course_url = "https://classes.uchicago.edu/search.php?Keyword=#{department}"
document = Nokogiri::HTML open( course_url )
@@ -98,10 +101,8 @@ def scrape_classes_website
# These xpath expressions are rock solid simple compared to ScheduleSpy 1.0, but a
# more complete implementation might scrape course activities as well.
document.xpath('//tr[@class="resultrow"]').each do |r|
- puts r
result = {
:course_name => r.xpath('td[@class="one"]/span[@class="name"]').text.strip,
- :location => nil,
:title => r.xpath('td[@class="two"]').text.strip,
:schedule => r.xpath('td[@class="four"]').text.strip,
:enrollment => r.xpath('td[@class="six"]').text.strip,
@@ -110,8 +111,6 @@ def scrape_classes_website
:url => course_url,
}
- puts result
-
unless result[:title].blank?
# We're only going to parse these down further
course_name = result.delete :course_name
View
2  app/views/layouts/application.html.haml
@@ -24,5 +24,5 @@
%p.flash{:class => type} <strong>#{type.capitalize}</strong>: #{text}
#content= yield
%footer
- %p 2011 <a href="http://www.facebook.com/sczizzo" title="Sean Clemmer">Sean Clemmer</a> and <a href="http://www.facebook.com/paulkaplan74" title="Paul Kaplan">Paul Kaplan</a>
+ %p 2012 <a href="http://www.facebook.com/sczizzo" title="Sean Clemmer">Sean Clemmer</a> and <a href="http://www.facebook.com/paulkaplan74" title="Paul Kaplan">Paul Kaplan</a>
#debug= debug params if Rails.env.development?
View
6 app/workers/schedule_spy.rb
@@ -7,10 +7,6 @@ class ScheduleSpy
def self.perform course_id, spy_ids=nil
course = Course.find(course_id)
course.look_up
-
- if spy_ids
- spies = Spy.find spy_ids
- course.notify_all spies
- end
+ course.notify_all spy_ids
end
end
View
24 db/schema.rb
@@ -17,8 +17,8 @@
t.integer "user_id"
t.string "provider"
t.string "uid"
- t.datetime "created_at"
- t.datetime "updated_at"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
t.string "token"
end
@@ -35,8 +35,8 @@
t.integer "quarter"
t.datetime "expires_at"
t.datetime "spied_at"
- t.datetime "created_at"
- t.datetime "updated_at"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
t.string "url"
t.string "last_status"
end
@@ -47,8 +47,8 @@
t.string "department"
t.integer "number"
t.string "section"
- t.datetime "created_at"
- t.datetime "updated_at"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
end
add_index "spies", ["course_id"], :name => "index_spies_on_course_id"
@@ -56,19 +56,19 @@
create_table "users", :force => true do |t|
t.string "name"
- t.integer "roles_mask", :default => 2, :null => false
- t.string "email", :default => "", :null => false
- t.string "encrypted_password", :limit => 128, :default => "", :null => false
+ t.integer "roles_mask", :default => 2, :null => false
+ t.string "email", :default => "", :null => false
+ t.string "encrypted_password", :default => "", :null => false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
- t.integer "sign_in_count", :default => 0
+ t.integer "sign_in_count", :default => 0
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
- t.datetime "created_at"
- t.datetime "updated_at"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
t.string "permalink"
t.string "token"
end
Please sign in to comment.
Something went wrong with that request. Please try again.