Skip to content

Commit

Permalink
Added website to Organization and a method for finding the 'official'…
Browse files Browse the repository at this point in the history
… website.
  • Loading branch information
driki committed Feb 21, 2012
1 parent 085ea5b commit 5e39166
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 35 deletions.
16 changes: 8 additions & 8 deletions Gemfile
Expand Up @@ -24,7 +24,7 @@ gem 'acts-as-taggable-on', '~> 2.2.2'
gem 'tabs_on_rails'
gem 'simple_form', git: 'git://github.com/plataformatec/simple_form.git'
gem 'ffaker'
gem 'flickraw'
gem 'ken'
gem 'best_in_place'
gem 'activerecord-import'
gem 'differ'
Expand Down Expand Up @@ -61,13 +61,13 @@ group :development, :test do
gem 'rspec-rails'
gem 'capybara'
gem 'shoulda-matchers'
gem 'guard'
gem 'spork', '> 0.9.0.rc'
gem 'growl'
gem 'rb-fsevent'
gem 'guard-bundler'
gem 'guard-rspec'
gem 'guard-spork'
# gem 'guard'
# gem 'spork', '> 0.9.0.rc'
# gem 'growl'
# gem 'rb-fsevent'
# gem 'guard-bundler'
# gem 'guard-rspec'
# gem 'guard-spork'
gem 'sqlite3'
end

Expand Down
29 changes: 6 additions & 23 deletions Gemfile.lock
Expand Up @@ -77,6 +77,7 @@ GEM
erubis (2.7.0)
execjs (1.3.0)
multi_json (~> 1.0)
extlib (0.9.15)
factory_girl (2.5.0)
activesupport
factory_girl_rails (1.6.0)
Expand All @@ -88,28 +89,19 @@ GEM
rack (~> 1.1)
ffaker (1.12.1)
ffi (1.0.11)
flickraw (0.9.5)
geocoder (1.1.0)
geoip (1.1.2)
growl (1.0.3)
guard (1.0.0)
ffi (>= 0.5.0)
thor (~> 0.14.6)
guard-bundler (0.1.3)
bundler (>= 1.0.0)
guard (>= 0.2.2)
guard-rspec (0.6.0)
guard (>= 0.10.0)
guard-spork (0.5.1)
guard (>= 0.10.0)
spork (>= 0.8.4)
hashie (1.2.0)
hike (1.2.1)
i18n (0.6.0)
jquery-rails (1.0.19)
railties (~> 3.0)
thor (~> 0.14)
json (1.6.5)
ken (0.2.1)
addressable
extlib
json
mail (2.3.0)
i18n (>= 0.4.0)
mime-types (~> 1.16)
Expand Down Expand Up @@ -169,7 +161,6 @@ GEM
rdoc (~> 3.4)
thor (~> 0.14.6)
rake (0.9.2.2)
rb-fsevent (0.4.3.1)
rdoc (3.12)
json (~> 1.4)
refraction (0.2.0)
Expand Down Expand Up @@ -214,7 +205,6 @@ GEM
slim (1.1.0)
temple (~> 0.3.5)
tilt (~> 1.3.2)
spork (1.0.0rc0)
sprockets (2.0.3)
hike (~> 1.2)
rack (~> 1.0)
Expand Down Expand Up @@ -254,15 +244,10 @@ DEPENDENCIES
differ
factory_girl_rails
ffaker
flickraw
geocoder
geoip
growl
guard
guard-bundler
guard-rspec
guard-spork
jquery-rails
ken
money
mysql2
newrelic_rpm
Expand All @@ -272,7 +257,6 @@ DEPENDENCIES
paper_trail
pg
rails (= 3.1.3)
rb-fsevent
refraction
rest-client
roar-rails
Expand All @@ -281,7 +265,6 @@ DEPENDENCIES
shoulda-matchers
simple_form!
slim
spork (> 0.9.0.rc)
sqlite3
tabs_on_rails
turn (= 0.8.2)
Expand Down
22 changes: 22 additions & 0 deletions app/models/organization.rb
Expand Up @@ -40,6 +40,28 @@ def price
return price
end

def load_official_website
topic = nil
website = nil
begin
topic = Ken::Topic.get("/en/#{name.downcase}_#{helper.states[state].downcase}")
rescue Exception => e
begin
topic = Ken::Topic.get("/en/#{name.downcase}")
rescue Exception => e
end
end
if !topic.nil?
webpages = topic.webpages
#Official website pages are first and have a value of {name}
if webpages[0]["text"].eql?("{name}")
website = webpages[0]["url"]
self.website = website
self.save
end
end
end

def self.load_census(state_abbriviation)
api_key = "8gybnk94e8uyt5vzv9enzpyz"
url = "http://api.usatoday.com/open/census/loc?keypat=#{state_abbriviation}&sumlevid=4,6&api_key=#{api_key}"
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20120221001126_add_website_to_organization.rb
@@ -0,0 +1,5 @@
class AddWebsiteToOrganization < ActiveRecord::Migration
def change
add_column :organizations, :website, :string
end
end
7 changes: 4 additions & 3 deletions db/schema.rb
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20120202123042) do
ActiveRecord::Schema.define(:version => 20120221001126) do

create_table "categories", :force => true do |t|
t.string "name"
Expand Down Expand Up @@ -88,6 +88,7 @@
t.integer "employee_count"
t.string "type"
t.string "slug"
t.string "website"
end

add_index "organizations", ["latitude", "longitude"], :name => "index_organizations_on_latitude_and_longitude"
Expand All @@ -103,8 +104,8 @@
t.integer "year"
t.float "average_tax_bill", :default => 0.0
t.boolean "enable_comments", :default => true
t.boolean "enable_tips"
t.boolean "is_demo"
t.boolean "enable_tips", :default => false
t.boolean "is_demo", :default => false
t.integer "organization_id"
t.datetime "created_at"
t.datetime "updated_at"
Expand Down
11 changes: 10 additions & 1 deletion lib/tasks/populate.rake
@@ -1,7 +1,7 @@
require "#{Rails.root}/app/helpers/application_helper"
include ApplicationHelper

namespace :db do
namespace :nearbyfyi do
desc "Fill database"

task :populate_organizations => :environment do
Expand Down Expand Up @@ -36,4 +36,13 @@ namespace :db do
org.save
end
end

desc "Collect official government websites"
task :collect_websites, [:city, :state] => :environment do
orgs = Organization.limit(100)
orgs.each do |org|
puts "STARTING: #{org.name}, #{org.state} TIME: #{Time.now.asctime}"
org.load_official_website
end
end
end

0 comments on commit 5e39166

Please sign in to comment.