hulse 0.6 → 0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 24805bee84bd7c6a90544f7d70c98c0eb32661c2
4
- data.tar.gz: f8e91bcffaca717a42d71e1f5bd1903fa52da684
3
+ metadata.gz: fb2a99da5c608cdd21b613eedec185ed0c2d68db
4
+ data.tar.gz: cb4502cab20752d48fe70929db54071122509dc9
5
5
  SHA512:
6
- metadata.gz: 3171a1108d9677464ff0ddd67f3780ae37128dd0118f68efba14215f1033647ebd92fd19d6da0fbf7d7e14a14dce7649ddd17a48f702638f6770a393e06465eb
7
- data.tar.gz: c7739d66a725f05131c0d4e696a6647bd0c2b535eb453a9ef06b52a53e26459516673e1a420b097936aed8da074bbdfaa5acdcad1187151b8074255d7c6e9e34
6
+ metadata.gz: 30d9cdfe34eb025d37f95b01e63b73711b562a96d5405ae74b92a8850a3839559f8e0998258804fb5902e197d7e1955595740227d4482332cc6d71ce4f06c489
7
+ data.tar.gz: 38ba6c3b5b72b4a85ef54bdb448738e1f612427d3b990765bcdef0dd146f7cfc3289e7d66baf87e7246df4f5981b42e7b65e40074a95cc094ca13d52a349a273
data/README.md CHANGED
@@ -6,12 +6,14 @@ Hulse can be used to get House and Senate roll call votes from the official sour
6
6
 
7
7
  Hulse has two vote classes, `HouseVote` and `SenateVote`, which create Ruby objects using the XML attributes available from roll call vote data (voice votes are not covered by Hulse or available as data from official sources). Hulse makes a few changes, renaming some attributes for clarity and consistency, and collapsing each House vote's date and time into a single datetime attribute. Otherwise it does not alter the original data.
8
8
 
9
- `HouseVote` and `SenateVote` have different attributes due to parliamentary conventions and the presence or absence of data in one chamber or the other. Senators are uniquely identified by a `lis_member_id`; House members are uniquely identified by a `bioguide_id` beginning in 2003. Prior to 2003, there is no unique ID for House members, but using a combination of name, state and political party one can be manufactured. House member attributes also include an `unaccented_name` and a `name` attribute that may contain accent characters.
9
+ `HouseVote` and `SenateVote` have different attributes due to parliamentary conventions and the presence or absence of data in one chamber or the other. Senators are uniquely identified by a `lis_member_id`; House members are uniquely identified by a `bioguide_id` beginning in 2003. Prior to 2003, there is no unique ID for House members, but using a combination of name, state and political party one can be manufactured. House member attributes also include an `unaccented_name` and a `name` attribute that may contain accent characters. Both `HouseVote` and `SenateVote` have class methods that will return the number of the latest vote in each chamber.
10
10
 
11
11
  Hulse also has two member classes, `HouseMember` and `SenateMember`, which create Ruby objects using the XML made available by the Clerk of the House and the Secretary of the Senate. House members have some basic information, including the unique `bioguide_id`, along with office details and committee and subcommittee assignment data. For vacant seats, information on the seat's previous occupant is available. Senate members have less information, but their data includes the Senate class and the URLs of their websites and email forms.
12
12
 
13
13
  Hulse has two other classes, `HouseFloor` and `Record`. The former provides a wrapper to [XML data on floor activity](http://clerk.house.gov/floorsummary/floor.aspx?day=20150729) published by the Clerk of the House, including timestamps and descriptions. The `Record` class provides a basic wrapper to the [Congressional Record](https://www.congress.gov/congressional-record), the daily listing of activities by the House and Senate, as well as some methods for accessing specific portions of it, particularly the titles and permalinks of articles.
14
14
 
15
+ Lastly, if you ever need to convert a year to its corresponding congress and session numbers, Hulse has a utility method for doing so.
16
+
15
17
  Hulse is named for [Carl Hulse](https://www.nytimes.com/learning/students/ask_reporters/Carl_Hulse.html), a longtime congressional correspondent for The New York Times.
16
18
 
17
19
  ## Installation
@@ -10,6 +10,13 @@ module Hulse
10
10
  end
11
11
  end
12
12
 
13
+ def self.latest_vote(year)
14
+ url = "http://clerk.house.gov/evs/#{year}/index.asp"
15
+ response = HTTParty.get(url)
16
+ doc = Nokogiri::HTML(response.parsed_response)
17
+ (doc/:a).first.text.to_i
18
+ end
19
+
13
20
  def self.find(year, vote)
14
21
  url = "http://clerk.house.gov/evs/#{year.to_s}/roll#{vote.to_s.rjust(3,"0")}.xml"
15
22
  response = HTTParty.get(url)
@@ -25,11 +32,13 @@ module Hulse
25
32
  end
26
33
  members = []
27
34
  mappings = {"__content__" => "name"}
28
- response['vote_data']['recorded_vote'].each do |m|
29
- m['legislator']['name'] = m['legislator'].delete('__content__')
30
- m['legislator']['bioguide_id'] = m['legislator'].delete('name_id') # prior to 2003, bioguide IDs were not used in the XML
31
- m['legislator']['vote'] = m['vote']
32
- members << m['legislator'].inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
35
+ if response['vote_data']
36
+ response['vote_data']['recorded_vote'].each do |m|
37
+ m['legislator']['name'] = m['legislator'].delete('__content__')
38
+ m['legislator']['bioguide_id'] = m['legislator'].delete('name_id') # prior to 2003, bioguide IDs were not used in the XML
39
+ m['legislator']['vote'] = m['vote']
40
+ members << m['legislator'].inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
41
+ end
33
42
  end
34
43
  if response['vote_metadata']['vote_question'] == 'Election of the Speaker'
35
44
  vote_counts = response['vote_metadata']['vote_totals']['totals_by_candidate'].reject{|k,v| k == 'total_stub'}.inject({}){|memo,(k,v)| memo[k['candidate'].to_sym] = k['candidate_total'].to_i; memo}
@@ -47,7 +56,7 @@ module Hulse
47
56
  amendment_author: response['vote_metadata']['amendment_author'],
48
57
  vote_type: response['vote_metadata']['vote_type'],
49
58
  vote_result: response['vote_metadata']['vote_result'],
50
- vote_timestamp: DateTime.parse(response['vote_metadata']['action_date'] + ' ' + response['vote_metadata']['action_time']['time_etz']),
59
+ vote_timestamp: begin DateTime.parse(response['vote_metadata']['action_date'] + ' ' + response['vote_metadata']['action_time']['time_etz']) rescue nil end,
51
60
  description: response['vote_metadata']['vote_desc'],
52
61
  party_summary: party_totals,
53
62
  vote_count: vote_counts,
@@ -2,7 +2,7 @@ module Hulse
2
2
  class SenateVote
3
3
 
4
4
  attr_reader :congress, :session, :year, :vote_number, :vote_timestamp, :updated_at, :vote_question_text, :vote_document_text,
5
- :vote_result_text, :question, :vote_title, :majority_requirement, :vote_result, :document, :amendment, :vote_count, :tie_breaker, :members,
5
+ :vote_result_text, :question, :vote_title, :majority_requirement, :vote_result, :document, :amendment, :vote_count, :tie_breaker, :members,
6
6
  :vote_date, :issue
7
7
 
8
8
  def initialize(params={})
@@ -10,7 +10,14 @@ module Hulse
10
10
  instance_variable_set("@#{k}", v)
11
11
  end
12
12
  end
13
-
13
+
14
+ def self.latest_vote(year)
15
+ congress, session = Hulse::Utils.convert_year_to_congress_and_session(year)
16
+ url = "http://www.senate.gov/legislative/LIS/roll_call_lists/vote_menu_#{congress}_#{session}.xml"
17
+ response = HTTParty.get(url)
18
+ response.parsed_response['vote_summary']['votes']['vote'].first['vote_number'].to_i
19
+ end
20
+
14
21
  def self.find(year, vote)
15
22
  congress, session = Hulse::Utils.convert_year_to_congress_and_session(year)
16
23
  url = "http://www.senate.gov/legislative/LIS/roll_call_votes/vote#{congress}#{session}/vote_#{congress}_#{session}_#{vote.to_s.rjust(5,"0")}.xml"
@@ -43,14 +50,14 @@ module Hulse
43
50
  members: members
44
51
  )
45
52
  end
46
-
53
+
47
54
  def self.summary(year)
48
55
  congress, session = Hulse::Utils.convert_year_to_congress_and_session(year)
49
56
  url = "http://www.senate.gov/legislative/LIS/roll_call_lists/vote_menu_#{congress}_#{session}.xml"
50
57
  response = HTTParty.get(url)
51
58
  return nil if response.code == 404
52
59
  votes = response.parsed_response['vote_summary']['votes']['vote']
53
- votes.map{|v| self.new(congress: congress, session: session, year: year, vote_number: v['vote_number'], vote_date: Date.strptime(v['vote_date']+"-#{year}", "%d-%b-%Y"), issue: v['issue'],
60
+ votes.map{|v| self.new(congress: congress, session: session, year: year, vote_number: v['vote_number'], vote_date: Date.strptime(v['vote_date']+"-#{year}", "%d-%b-%Y"), issue: v['issue'],
54
61
  question: v['question'], vote_result: v['result'], vote_count: v['vote_tally'].inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}, vote_title: v['title'])}
55
62
  end
56
63
  end
data/lib/hulse/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hulse
2
- VERSION = "0.6"
2
+ VERSION = "0.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hulse
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.6'
4
+ version: '0.7'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derek Willis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-03 00:00:00.000000000 Z
11
+ date: 2015-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler