Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed email issues, mayhaps?

  • Loading branch information...
commit 3e56bed1256a426f0e0d136c385cd2fe11c97ade 1 parent 0aa9169
Sean Clemmer authored
4 Gemfile
@@ -4,14 +4,13 @@ gem 'rails'
4 4 gem 'god'
5 5 gem 'foreman'
6 6 gem 'resque', :require => 'resque/server'
7   -# gem 'resque-scheduler'
  7 +gem 'resque-scheduler'
8 8 gem 'whenever', :require => false
9 9 gem 'high_voltage'
10 10 gem 'nokogiri'
11 11 gem 'devise'
12 12 gem 'cancan'
13 13 gem 'omniauth'
14   -# gem 'koala'
15 14
16 15 group :assets do
17 16 gem 'haml'
@@ -26,7 +25,6 @@ end
26 25
27 26 group :development, :test do
28 27 gem 'sqlite3'
29   - # gem 'ruby-debug19', :require => 'ruby-debug'
30 28 end
31 29
32 30 group :test do
7 Gemfile.lock
@@ -141,6 +141,12 @@ GEM
141 141 redis-namespace (~> 1.0.2)
142 142 sinatra (>= 0.9.2)
143 143 vegas (~> 0.1.2)
  144 + resque-scheduler (1.9.9)
  145 + redis (>= 2.0.1)
  146 + resque (>= 1.8.0)
  147 + rufus-scheduler
  148 + rufus-scheduler (2.0.16)
  149 + tzinfo (>= 0.3.23)
144 150 sass (3.1.15)
145 151 sinatra (1.3.2)
146 152 rack (~> 1.3, >= 1.3.6)
@@ -191,6 +197,7 @@ DEPENDENCIES
191 197 pg
192 198 rails
193 199 resque
  200 + resque-scheduler
194 201 sass-rails!
195 202 sqlite3
196 203 turn
41 app/models/course.rb
@@ -33,9 +33,9 @@ def self.look_up_all
33 33
34 34 # Handles caching the call to look up course information
35 35 # Note: Safe to call repeatedly (unless skip_cache), but you probably shouldn't
36   - def look_up skip_cache=false
  36 + def look_up skip_cache=true#false
37 37 if skip_cache or spied_at.nil? or spied_at < 5.minutes.ago
38   - unless scrape_classes_website
  38 + unless scrape_classes_website # i.e. unless the course was updated
39 39 # Well, at least we tried
40 40 update_attributes({
41 41 :spied_at => Time.now,
@@ -47,21 +47,27 @@ def look_up skip_cache=false
47 47
48 48 # Notify certain spies immediately, or all attached spies when necessary
49 49 # Note: Do not call repeatedly, will send out duplicate messages
50   - def notify_all spies=nil
51   - if spies or last_status != status
  50 + def notify_all spy_ids=nil
  51 + if last_status != status or spy_ids != nil
  52 + if spy_ids
  53 + spies_to_notify = Spy.find spy_ids
  54 + else
  55 + spies_to_notify = spies
  56 + end
  57 +
52 58 case status
53 59 # Will never be unspied
54 60 when 'no record found'
55   - notify spies, :course_not_found
  61 + notify spies_to_notify, :course_not_found
56 62 when 'consent required'
57   - notify spies, :consent_required
  63 + notify spies_to_notify, :consent_required
58 64 when 'no limit'
59   - notify spies, :no_limit
  65 + notify spies_to_notify, :no_limit
60 66 when 'open'
61   - notify spies, :opening_found
  67 + notify spies_to_notify, :opening_found
62 68 when 'closed'
63 69 if last_status.nil?
64   - notify spies, :course_found
  70 + notify spies_to_notify, :course_found
65 71 end
66 72 end
67 73 end
@@ -69,16 +75,15 @@ def notify_all spies=nil
69 75
70 76 # Send a message to a spy or list of spies
71 77 # Note: Do not call repeatedly, will send out duplicate messages
72   - def notify spies, mailer_method_name
73   - spies ||= self.spies
74   - spies = spies.respond_to?(:each) ? spies : [spies]
75   - spies.each do |spy|
  78 + def notify spies_to_notify, mailer_method_name
  79 + puts "**************\n\n\nNotifying\n\n\n***********************"
  80 + spies_to_notify ||= self.spies
  81 + spies_to_notify = [spies_to_notify] unless spies_to_notify.respond_to?(:each)
  82 + spies_to_notify.each do |spy|
76 83 SpyMailer.send(mailer_method_name, spy).deliver
77 84 end
78 85 end
79 86
80   -# private
81   -
82 87 # Heart of the data aquisition operation:
83 88 # Fortunately, the course website (classes.uchicago.edu) exposes a search
84 89 # function (search.php) and a course lookup function (courseDetail.php). This
@@ -89,8 +94,6 @@ def scrape_classes_website
89 94
90 95 # By NOT including the number argument, we do a lookup for the whole department
91 96 # In the end, this is much more efficient for both Classes and ScheduleSpy
92   - #
93   - # course_url = "https://classes.uchicago.edu/search.php?Keyword=#{department}%20#{number}&CourseLevel=Undergraduate&TermName=#{CURRENT_QUARTER_NAME}+#{CURRENT_YEAR}"
94 97 course_url = "https://classes.uchicago.edu/search.php?Keyword=#{department}"
95 98 document = Nokogiri::HTML open( course_url )
96 99
@@ -98,10 +101,8 @@ def scrape_classes_website
98 101 # These xpath expressions are rock solid simple compared to ScheduleSpy 1.0, but a
99 102 # more complete implementation might scrape course activities as well.
100 103 document.xpath('//tr[@class="resultrow"]').each do |r|
101   - puts r
102 104 result = {
103 105 :course_name => r.xpath('td[@class="one"]/span[@class="name"]').text.strip,
104   - :location => nil,
105 106 :title => r.xpath('td[@class="two"]').text.strip,
106 107 :schedule => r.xpath('td[@class="four"]').text.strip,
107 108 :enrollment => r.xpath('td[@class="six"]').text.strip,
@@ -110,8 +111,6 @@ def scrape_classes_website
110 111 :url => course_url,
111 112 }
112 113
113   - puts result
114   -
115 114 unless result[:title].blank?
116 115 # We're only going to parse these down further
117 116 course_name = result.delete :course_name
2  app/views/layouts/application.html.haml
@@ -24,5 +24,5 @@
24 24 %p.flash{:class => type} <strong>#{type.capitalize}</strong>: #{text}
25 25 #content= yield
26 26 %footer
27   - %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>
  27 + %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>
28 28 #debug= debug params if Rails.env.development?
6 app/workers/schedule_spy.rb
@@ -7,10 +7,6 @@ class ScheduleSpy
7 7 def self.perform course_id, spy_ids=nil
8 8 course = Course.find(course_id)
9 9 course.look_up
10   -
11   - if spy_ids
12   - spies = Spy.find spy_ids
13   - course.notify_all spies
14   - end
  10 + course.notify_all spy_ids
15 11 end
16 12 end
24 db/schema.rb
@@ -17,8 +17,8 @@
17 17 t.integer "user_id"
18 18 t.string "provider"
19 19 t.string "uid"
20   - t.datetime "created_at"
21   - t.datetime "updated_at"
  20 + t.datetime "created_at", :null => false
  21 + t.datetime "updated_at", :null => false
22 22 t.string "token"
23 23 end
24 24
@@ -35,8 +35,8 @@
35 35 t.integer "quarter"
36 36 t.datetime "expires_at"
37 37 t.datetime "spied_at"
38   - t.datetime "created_at"
39   - t.datetime "updated_at"
  38 + t.datetime "created_at", :null => false
  39 + t.datetime "updated_at", :null => false
40 40 t.string "url"
41 41 t.string "last_status"
42 42 end
@@ -47,8 +47,8 @@
47 47 t.string "department"
48 48 t.integer "number"
49 49 t.string "section"
50   - t.datetime "created_at"
51   - t.datetime "updated_at"
  50 + t.datetime "created_at", :null => false
  51 + t.datetime "updated_at", :null => false
52 52 end
53 53
54 54 add_index "spies", ["course_id"], :name => "index_spies_on_course_id"
@@ -56,19 +56,19 @@
56 56
57 57 create_table "users", :force => true do |t|
58 58 t.string "name"
59   - t.integer "roles_mask", :default => 2, :null => false
60   - t.string "email", :default => "", :null => false
61   - t.string "encrypted_password", :limit => 128, :default => "", :null => false
  59 + t.integer "roles_mask", :default => 2, :null => false
  60 + t.string "email", :default => "", :null => false
  61 + t.string "encrypted_password", :default => "", :null => false
62 62 t.string "reset_password_token"
63 63 t.datetime "reset_password_sent_at"
64 64 t.datetime "remember_created_at"
65   - t.integer "sign_in_count", :default => 0
  65 + t.integer "sign_in_count", :default => 0
66 66 t.datetime "current_sign_in_at"
67 67 t.datetime "last_sign_in_at"
68 68 t.string "current_sign_in_ip"
69 69 t.string "last_sign_in_ip"
70   - t.datetime "created_at"
71   - t.datetime "updated_at"
  70 + t.datetime "created_at", :null => false
  71 + t.datetime "updated_at", :null => false
72 72 t.string "permalink"
73 73 t.string "token"
74 74 end

0 comments on commit 3e56bed

Please sign in to comment.
Something went wrong with that request. Please try again.