Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add Wordnik word of day loading

  • Loading branch information...
commit 1adc7b6b939df4daafc7fab1c4f2bc15729b7a8f 1 parent 817fa4a
Ryan Daigle authored
1  Gemfile
View
@@ -10,6 +10,7 @@ gem 'make_resourceful'
gem 'dynamic_form'
gem 'wordnik'
gem 'queue_classic', '~> 1.0.1'
+gem 'clockwork'
gem 'haml'
gem 'jquery-rails'
119 Gemfile.lock
View
@@ -1,46 +1,47 @@
GEM
remote: http://rubygems.org/
specs:
- actionmailer (3.2.2)
- actionpack (= 3.2.2)
- mail (~> 2.4.0)
- actionpack (3.2.2)
- activemodel (= 3.2.2)
- activesupport (= 3.2.2)
+ actionmailer (3.2.3)
+ actionpack (= 3.2.3)
+ mail (~> 2.4.4)
+ actionpack (3.2.3)
+ activemodel (= 3.2.3)
+ activesupport (= 3.2.3)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.1)
rack (~> 1.4.0)
- rack-cache (~> 1.1)
+ rack-cache (~> 1.2)
rack-test (~> 0.6.1)
sprockets (~> 2.1.2)
- activemodel (3.2.2)
- activesupport (= 3.2.2)
+ activemodel (3.2.3)
+ activesupport (= 3.2.3)
builder (~> 3.0.0)
- activerecord (3.2.2)
- activemodel (= 3.2.2)
- activesupport (= 3.2.2)
+ activerecord (3.2.3)
+ activemodel (= 3.2.3)
+ activesupport (= 3.2.3)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
- activeresource (3.2.2)
- activemodel (= 3.2.2)
- activesupport (= 3.2.2)
- activesupport (3.2.2)
+ activeresource (3.2.3)
+ activemodel (= 3.2.3)
+ activesupport (= 3.2.3)
+ activesupport (3.2.3)
i18n (~> 0.6)
multi_json (~> 1.0)
- addressable (2.2.7)
+ addressable (2.2.8)
arel (3.0.2)
builder (3.0.0)
+ clockwork (0.4.0)
+ tzinfo
diff-lcs (1.1.3)
dynamic_form (1.1.4)
erubis (2.7.0)
- execjs (1.3.0)
+ execjs (1.3.1)
multi_json (~> 1.0)
- foreman (0.40.0)
- term-ansicolor (~> 1.0.7)
+ foreman (0.46.0)
thor (>= 0.13.6)
haml (3.1.4)
- heroku (2.21.3)
+ heroku (2.25.0)
launchy (>= 0.3.2)
netrc (~> 0.7.1)
rest-client (~> 1.6.1)
@@ -49,14 +50,14 @@ GEM
htmlentities (4.3.1)
i18n (0.6.0)
journey (1.0.3)
- jquery-rails (2.0.1)
+ jquery-rails (2.0.2)
railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
- json (1.6.5)
- kgio (2.7.2)
- launchy (2.0.5)
+ json (1.7.0)
+ kgio (2.7.4)
+ launchy (2.1.0)
addressable (~> 2.2.6)
- lograge (0.0.3)
+ lograge (0.0.4)
actionpack
activesupport
mail (2.4.4)
@@ -64,15 +65,15 @@ GEM
mime-types (~> 1.16)
treetop (~> 1.4.8)
make_resourceful (1.0.1)
- mime-types (1.17.2)
- multi_json (1.1.0)
+ mime-types (1.18)
+ multi_json (1.3.4)
netrc (0.7.1)
- newrelic_rpm (3.3.2)
+ newrelic_rpm (3.3.4.1)
nokogiri (1.5.2)
permalink_fu (1.0.0)
pg (0.11.0)
polyglot (0.3.3)
- queue_classic (1.0.1)
+ queue_classic (1.0.2)
pg (~> 0.11.0)
rack (1.4.1)
rack-cache (1.2)
@@ -81,19 +82,19 @@ GEM
rack
rack-test (0.6.1)
rack (>= 1.0)
- rails (3.2.2)
- actionmailer (= 3.2.2)
- actionpack (= 3.2.2)
- activerecord (= 3.2.2)
- activeresource (= 3.2.2)
- activesupport (= 3.2.2)
+ rails (3.2.3)
+ actionmailer (= 3.2.3)
+ actionpack (= 3.2.3)
+ activerecord (= 3.2.3)
+ activeresource (= 3.2.3)
+ activesupport (= 3.2.3)
bundler (~> 1.0)
- railties (= 3.2.2)
+ railties (= 3.2.3)
rails_log_stdout (0.1.1)
rails (~> 3.2.0)
- railties (3.2.2)
- actionpack (= 3.2.2)
- activesupport (= 3.2.2)
+ railties (3.2.3)
+ actionpack (= 3.2.3)
+ activesupport (= 3.2.3)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
@@ -104,30 +105,29 @@ GEM
json (~> 1.4)
rest-client (1.6.7)
mime-types (>= 1.16)
- rspec (2.8.0)
- rspec-core (~> 2.8.0)
- rspec-expectations (~> 2.8.0)
- rspec-mocks (~> 2.8.0)
- rspec-core (2.8.0)
- rspec-expectations (2.8.0)
- diff-lcs (~> 1.1.2)
- rspec-mocks (2.8.0)
- rspec-rails (2.8.1)
+ rspec (2.9.0)
+ rspec-core (~> 2.9.0)
+ rspec-expectations (~> 2.9.0)
+ rspec-mocks (~> 2.9.0)
+ rspec-core (2.9.0)
+ rspec-expectations (2.9.1)
+ diff-lcs (~> 1.1.3)
+ rspec-mocks (2.9.0)
+ rspec-rails (2.9.0)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
- rspec (~> 2.8.0)
- rubyzip (0.9.6.1)
- sass (3.1.15)
- sass-rails (3.2.4)
+ rspec (~> 2.9.0)
+ rubyzip (0.9.8)
+ sass (3.1.16)
+ sass-rails (3.2.5)
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
- sprockets (2.1.2)
+ sprockets (2.1.3)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
- term-ansicolor (1.0.7)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
@@ -135,16 +135,16 @@ GEM
polyglot (>= 0.3.1)
typhoeus (0.3.3)
mime-types
- tzinfo (0.3.32)
- uglifier (1.2.3)
+ tzinfo (0.3.33)
+ uglifier (1.2.4)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
- unicorn (4.2.0)
+ unicorn (4.3.1)
kgio (~> 2.6)
rack
raindrops (~> 0.7)
will_paginate (3.0.3)
- wordnik (4.06.15)
+ wordnik (4.07)
activemodel (>= 3.0.3)
addressable (>= 2.2.4)
htmlentities (>= 4.2.4)
@@ -156,6 +156,7 @@ PLATFORMS
ruby
DEPENDENCIES
+ clockwork
dynamic_form
foreman
haml
3  Procfile
View
@@ -1,2 +1,3 @@
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
-queue: bundle exec rake jobs:work
+worker: bundle exec rake jobs:work
+clock: bundle exec clockwork clock.rb
28 app/loaders/wordnik_wod_loader.rb
View
@@ -0,0 +1,28 @@
+require 'wordnik'
+
+class WordnikWODLoader
+
+ class << self
+
+ def load!(from = Date.today)
+ subject = Subject.find(ENV['VOCABULARY_SUBJECT_ID'])
+ if(subject)
+ today = Date.today
+ while(from <= today)
+ load_wod(subject, from)
+ from = from + 1.day
+ end
+ end
+ end
+
+ def load_wod(subject, day)
+ result = question = nil
+ log(subject, "day=\"#{day}\"") do
+ result = Wordnik.words.get_word_of_the_day(date: day.strftime("%Y-%m-%d"))
+ question = result && !result.empty? ? result['word'] : nil
+ existing_question = subject.units.where(question: question).first
+ subject.units.create(question: question) unless existing_question
+ end
+ end
+ end
+end
1  app/models/subject.rb
View
@@ -1,5 +1,4 @@
require 'csv'
-require 'processors/wordnik_processor'
class Subject < ActiveRecord::Base
2  app/models/unit_observer.rb
View
@@ -3,6 +3,6 @@ class UnitObserver < ActiveRecord::Observer
observe :unit
def after_create(unit)
- log(unit) { $queue.enqueue('Unit.process!', unit.id) }
+ # log(unit) { $queue.enqueue('Unit.process!', unit.id) }
end
end
0  app/models/processors/google_translate_processor.rb → app/processors/google_translate_processor.rb
View
File renamed without changes
0  app/models/processors/wordnik_processor.rb → app/processors/wordnik_processor.rb
View
File renamed without changes
8 clock.rb
View
@@ -0,0 +1,8 @@
+require ::File.expand_path('../config/environment', __FILE__)
+include Clockwork
+
+handler do |job|
+ $queue.enqueue(job)
+end
+
+every(30.seconds, "WordnikWODLoader.load!")
Please sign in to comment.
Something went wrong with that request. Please try again.