Skip to content

Commit

Permalink
Merge branch 'production'
Browse files Browse the repository at this point in the history
  • Loading branch information
opencongress committed Oct 18, 2011
2 parents 6ca3bcb + ac5baf5 commit 5767790
Show file tree
Hide file tree
Showing 17 changed files with 116 additions and 77 deletions.
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class ApplicationController < ActionController::Base
protect_from_forgery

include AuthenticatedSystem
# include SimpleCaptcha::ControllerHelpers
include SimpleCaptcha::ControllerHelpers
include Facebooker2::Rails::Controller
include UrlHelper

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/bill_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ def major
@sort = 'major'
@title_desc = SiteText.find_title_desc('bill_hot')
@types = 'all'
@hot_bill_categories = PvsCategory.find(:all, :order => :name)
@atom = {'link' => "/bill/major.rss", 'title' => "Major Bills"}
@congress = params[:congress].blank? ? Settings.default_congress : params[:congress]
@hot_bill_categories = PvsCategory.includes(:hot_bills).where(["bills.session = ?", @congress]).order("pvs_categories.name")

respond_to do |format|
format.html {}
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def create
@group.user = current_user

respond_to do |format|
if @group.save
if @group.save_with_captcha
format.html { redirect_to(new_group_group_invite_path(@group, :new => true), :notice => 'Group was successfully created.') }
format.xml { render :xml => @group, :status => :created, :location => @group }
else
Expand Down
2 changes: 2 additions & 0 deletions app/models/group.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class Group < ActiveRecord::Base
has_attached_file :group_image, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :path => "#{Settings.group_images_path}/:id/:style/:filename"

apply_simple_captcha

validates_presence_of :name
validates_uniqueness_of :name
validates_presence_of :user_id
Expand Down
7 changes: 2 additions & 5 deletions app/models/zipcode_district.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
class ZipcodeDistrict < ActiveRecord::Base
def ZipcodeDistrict.zip_lookup(zip5, zip4 = nil)
if zip4.blank?
find(:all, :select => "DISTINCT state, district",
:conditions => ["zip5 = ?", zip5])
self.select("DISTINCT state, district").where(["zip5 = ?", zip5]).all
else
find(:all, :select => "DISTINCT state, district",
:conditions => ["zip5 = ? AND (zip4 = ? OR zip4 = 'xxxx')", zip5, zip4])

self.select("DISTINCT state, district").where(["zip5 = ? AND (zip4 = ? OR zip4 = 'xxxx')", zip5, zip4]).all
end
end

Expand Down
12 changes: 12 additions & 0 deletions app/views/bill/_hot_bills.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@
This page of "Hot Bills" lists 46 issue areas, created and maintained by the non-profit, non-partisan <a href="http://votesmart.org/issue_rating.php">Project Vote Smart</a>. Bills in Congress are then assigned to issue areas by OpenCongress site editors (<a href="/about/staff">about our staff</a>). Bills may be assigned to more than one issue area, where applicable. Of the bills included here, many are actively moving through the legislative process towards becoming law. Some have already been voted on by Congress, and some are not moving in Congress, but have gained a lot of interest from the public and the media. Generally, then, these are the bills that people focus on when considering Congress' recent actions on these issues.
</div>

<div id="major_category_links">
<p>
<strong>Jump to:</strong>
<% @hot_bill_categories.each do |c| %>
<% if c.hot_bills.any? %>
<%= link_to c.name, "##{c.name}" %>
<%= "&bull;".html_safe unless c == @hot_bill_categories.last %>
<% end %>
<% end %>
</p>
</div>

<div class="hot_bill_collection">
<%= render :partial => 'hot_bill_category', :collection => @hot_bill_categories %>
</div>
3 changes: 2 additions & 1 deletion app/views/bill/major.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<% @content_for_sortby = render :partial => 'sort_bills', :locals => { :sort => 'hot'} %>


<div id="the-bills">
<%= render :partial => 'hot_bills', :locals => { :hot_bill_categories => @hot_bill_categories } %>
<%= render :partial => 'hot_bills', :locals => { :hot_bill_categories => @hot_bill_categories } %>
</div>
9 changes: 9 additions & 0 deletions app/views/groups/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@
= image_tag(@group.group_image.url(:thumb))
= f.label :group_image, 'Group image'
= f.file_field :group_image
- if @group.new_record?
%p
= f.simple_captcha :label => "Spam check"

.clear

:javascript
$j(document).ready(function() {
$j('input#group_captcha').addClass("field");
});
%p
= f.submit @group.new_record? ? 'Create Group' : 'Update Group', :class => 'button blue huge'
2 changes: 1 addition & 1 deletion app/views/groups/_groups_list.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
$j('#group_search_field').change(doSearch);
$j('#group_issue').change(doSearch);

$j('.table_header a').click(function() {
$j('.table_header a').live("click", function(e) {
if (($j(this).attr('class') == '') || ($j(this).attr('class') == 'down')) {
$j('.table_header a').attr('class', '');
$j(this).attr('class', 'up');
Expand Down
4 changes: 2 additions & 2 deletions app/views/people/compare.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<div>
<div class="comppeeps">
<h3><%= link_to @person1.full_name, :controller => 'people', :action => 'show', :id => @person1.ident %></h3>
<%= link_to(image_path(@person1.photo_path, :alt=> @person1.full_name), :controller => 'people', :action => 'show', :id => @person1.ident) %>
<%= link_to(image_tag(@person1.photo_path, :alt=> @person1.full_name).html_safe, :controller => 'people', :action => 'show', :id => @person1.ident) %>
<p>
<b>State:</b> <%= @person1.state %><br/>
<b>Party:</b> <%= @person1.party %><br/>
Expand All @@ -55,7 +55,7 @@
</div>
<div class="comppeeps right">
<h3><%= link_to @person2.full_name, :controller => 'people', :action => 'show', :id => @person2.ident %></h3>
<%= link_to(image_path(@person2.photo_path, :alt=> @person2.full_name), :controller => 'people', :action => 'show', :id => @person2.ident) %>
<%= link_to(image_tag(@person2.photo_path, :alt=> @person2.full_name).html_safe, :controller => 'people', :action => 'show', :id => @person2.ident) %>
<p>
<b>State:</b> <%= @person2.state %><br/>
<b>Party:</b> <%= @person2.party %><br/>
Expand Down
43 changes: 3 additions & 40 deletions app/views/simple_captcha/_simple_captcha.erb
Original file line number Diff line number Diff line change
@@ -1,42 +1,5 @@
<!-- Copyright (c) 2007 [Sur http://expressica.com] -->

<style type="text/CSS">

#simple_captcha{border: 1px solid #ccc; padding: 5px !important;}
#simple_captcha,
#simple_captcha div{display: table;}
#simple_captcha .simple_captcha_field,
#simple_captcha .simple_captcha_image{
border: 1px solid #ccc;
margin: 0px 0px 2px 0px !important;
padding: 0px !important;
}
#simple_captcha .simple_captcha_image img{
margin: 0px !important;
padding: 0px !important;
width: 110px !important;
}
#simple_captcha .simple_captcha_label{font-size: 12px;}
#simple_captcha .simple_captcha_field input{
width: 150px !important;
font-size: 16px;
border: none;
background-color: #efefef;
}
</style>



<div class='simple_captcha'>
<div class='simple_captcha_image'>
<%= simple_captcha_options[:image] %>
</div>

<div class='simple_captcha_field'>
<%= simple_captcha_options[:field] %>
</div>

<div class='simple_captcha_label'>
<%= simple_captcha_options[:label] %>
</div>
</div>
<label for="simple_captcha">Spam check</label>
<span class="captcha_img"><%= simple_captcha_options[:image] %></span>
<%= simple_captcha_options[:field] %>
4 changes: 3 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ en:

simple_captcha:
label: "Enter the text from the image"

message:
group: "The spam check value did not match the text in the image"

errors:
messages:
carrierwave_processing_error: 'Cannot resize image.'
Expand Down
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
resources :notebook_files
end
end


resources :simple_captcha, :only => :show

match '/' => 'index#index', :as => :home

# Allow downloading Web Service WSDL as a file with an extension
Expand Down
71 changes: 54 additions & 17 deletions lib/commentary_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
module CommentaryParser
USERAGENT = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1'
STOP_REFERRERS = [ "google\.com" ]
@@proxies = []
@@proxy = nil

def CommentaryParser.save_items(items, lookup_object, type, scraped_from)
n = items ? items.size : 0
Expand Down Expand Up @@ -302,32 +304,32 @@ def CommentaryParser.get_google_blog_items_for_query(query)
path = "/search?hl=en&ie=UTF-8&q=#{query}&tbm=blg"

begin
body = get_body_for_host_and_path(host, path)


OCLogger.log "\n\n\n\n\n\n\nGOT BODY: #{body}\n\n\n\n\n\n\n\n\n\n"

body = get_body_for_host_and_path(host, path)

doc = Hpricot(body)

posts = doc/"li.g"

place = 0
posts.each do |d|
#OCLogger.log "\n\n\n\n\n\n\nGOT SNIP: #{d}\n\n\n\n\n\n\n\n\n\n"
title_a = d.at("h3.r a")

unless title_a.inner_html =~ /Related blogs about/
unless (title_a.inner_html =~ /Related blogs about/ or
title_a.inner_html =~ /Blog homepages for/)
os = OpenStruct.new

os.title = (title_a.inner_html)
os.url = title_a.attributes["href"]


date_source = d.at(".f").inner_html
if date_source =~ / by /
os.date, os.source = date_source.split(/ by /)
else
os.date = date_source
date_source = d.at(".f")
if date_source
if date_source.inner_html =~ / by /
os.date, os.source = date_source.inner_html.split(/ by /)
else
os.date = date_source.inner_html
end
end

os.source = d.at("cite a").inner_html if os.source.nil?
Expand All @@ -351,16 +353,51 @@ def CommentaryParser.get_google_blog_items_for_query(query)
end

def CommentaryParser.get_body_for_host_and_path(host, path)
$DEBUG = false

begin
response = nil;
http = Net::HTTP.new(host)
http.start do |http|
request = Net::HTTP::Get.new(path, {"User-Agent" => USERAGENT})
response = http.request(request)
if @@proxies.empty?
m = Mechanize.new
m.user_agent_alias = "Windows IE 7"

m.get("http://hidemyass.com/proxy-list/search-235102")

p = m.page.parser
p.css('#listtable tr').each_with_index do |row, i|
unless i == 0
ip = row.css('td')[1].css('span').first

unless ip.attributes['title'] == 'Planet Lab proxy'
@@proxies << [ip.text,row.css('td')[2].text.strip]
end
end
end
end

begin
if @@proxy.nil?
use_proxy = @@proxies[rand(@@proxies.size)]
else
use_proxy = @@proxy
end

puts "Trying proxy: #{use_proxy[0]}:#{use_proxy[1]}..."

response = nil;
Net::HTTP::Proxy(use_proxy[0], use_proxy[1]).start(host) do |http|
request = Net::HTTP::Get.new(path, {"User-Agent" => USERAGENT})
begin
response = http.request(request)
rescue Timeout::Error
response = nil
end
end
end while !response.kind_of? Net::HTTPSuccess
@@proxy = use_proxy if @@proxy.nil?

return response.body
rescue
OCLogger.log "Error or timeout retrieving url: #{host}#{path}. Skipping."
OCLogger.log "Error or timeout retrieving url: #{host}#{path}. #{$!}. Skipping."
return "<html></html>"
end
end
Expand Down
9 changes: 6 additions & 3 deletions lib/yahoo_geocoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@ def geocode
require 'hpricot'
require 'open-uri'
begin
doc = Hpricot.XML(open("http://local.yahooapis.com/MapsService/V1/geocode?appid=#{@key}&location=#{CGI::escape(@address)}"))
doc = Hpricot.XML(open("http://where.yahooapis.com/geocode?q=#{CGI::escape(@address)}&appid=#{@key}"))


#puts "\n\n\nHERE's the DOC: #{doc}\n\n\n"
if doc
zip = (doc/:Result/:Zip).inner_html
zip = (doc/:Result/:postal).inner_html
@zip5,@zip4 = zip.split('-')
@city = (doc/:Result/:City).inner_html
@city = (doc/:Result/:city).inner_html
return true
else
return false
end
rescue
logger.warn "Error with Yahoo API: #{$!}"
return false
end
end
Expand Down
8 changes: 5 additions & 3 deletions public/stylesheets/bill.css
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ padding-right: 14px;
display: block;
text-align: center;
font-weight: bold;
font-family: Helvetica, Arial, sans-serif;
font-family: Helvetica, Arial, sans-serif;
color: #879f4e;
height: 44px;
padding-top: 8px;
Expand Down Expand Up @@ -803,7 +803,7 @@ font-size: 10.5px;
margin-top: 25px;
padding-top: 13px;
padding-bottom: 25px;
font-family: Helvetica, Arial, sans-serif;
font-family: Helvetica, Arial, sans-serif;
}

#bill-status-box table {
Expand Down Expand Up @@ -2467,7 +2467,9 @@ color: #888;
font-size: 11px;
}


#major_category_links {
margin-top: 20px;
}



Expand Down
9 changes: 9 additions & 0 deletions public/stylesheets/groups.css
Original file line number Diff line number Diff line change
Expand Up @@ -661,3 +661,12 @@ background: url(/images/issue-bg.png) 0 0 no-repeat;
.dummy_div, .dummy_li {
display: none;
}

.captcha_img {
float: left;
margin-bottom: 30px;
}
input#group_captcha {
float: left;
width: 100px;
}

0 comments on commit 5767790

Please sign in to comment.