Skip to content

Commit

Permalink
update bill urls
Browse files Browse the repository at this point in the history
  • Loading branch information
dwillis committed Dec 12, 2016
1 parent 8918b61 commit 52adca5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
2 changes: 1 addition & 1 deletion models/bill.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ class Bill

# for internal use in keeping upcoming field up to date
index "upcoming.source" => 1
end
end
32 changes: 14 additions & 18 deletions tasks/bills/bills.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ def self.run(options = {})

def self.sponsor_for(sponsor, legislators)
# cached by thomas ID
if legislators[sponsor['thomas_id']]
legislators[sponsor['thomas_id']]
elsif legislator = legislator_for(sponsor['thomas_id'])
if legislators[sponsor['bioguide_id']]
legislators[sponsor['bioguide_id']]
elsif legislator = legislator_for(sponsor['bioguide_id'])
# cache it for next time
legislators[sponsor['thomas_id']] = legislator
legislators[sponsor['bioguide_id']] = legislator
legislator
else
# no match, this needs to get reported
Expand All @@ -192,6 +192,7 @@ def self.history_for(history)
new_history
end

# change this to not use thomas_id
def self.cosponsors_for(cosponsors, legislators)
new_cosponsors = []
withdrawn_cosponsors = []
Expand All @@ -200,11 +201,11 @@ def self.cosponsors_for(cosponsors, legislators)
cosponsors.each do |cosponsor|
person = nil

if legislators[cosponsor['thomas_id']]
person = legislators[cosponsor['thomas_id']]
elsif person = legislator_for(cosponsor['thomas_id'])
if legislators[cosponsor['bioguide_id']]
person = legislators[cosponsor['bioguide_id']]
elsif person = legislator_for(cosponsor['bioguide_id'])
# cache it for next time
legislators[cosponsor['thomas_id']] = person
legislators[cosponsor['bioguide_id']] = person
end

if person
Expand Down Expand Up @@ -311,8 +312,8 @@ def self.committees_for(elements, committee_cache)
[committees, missing]
end

def self.legislator_for(thomas_id)
legislator = Legislator.where(thomas_id: thomas_id).first
def self.legislator_for(bioguide_id)
legislator = Legislator.where(bioguide_id: bioguide_id).first
legislator ? Utils.legislator_for(legislator) : nil
end

Expand Down Expand Up @@ -351,22 +352,17 @@ def self.urls_for(bill_id)
type, number, congress, chamber = Utils.bill_fields_from bill_id
{
congress: congress_gov_url(congress, type, number),
govtrack: govtrack_url(congress, type, number),
opencongress: opencongress_url(bill_id)
govtrack: govtrack_url(congress, type, number)
}
end

def self.opencongress_url(bill_id)
"https://www.opencongress.org/bill/#{bill_id}"
end

def self.govtrack_url(congress, type, number)
"https://www.govtrack.us/congress/bills/#{congress}/#{type}#{number}"
end

# todo: when they expand to earlier (or later) congresses, 'th' is not a universal ordinal
def self.congress_gov_url(congress, type, number)
"http://beta.congress.gov/bill/#{congress}th/#{congress_gov_type type}/#{number}"
"https://www.congress.gov/bill/#{congress}th/#{congress_gov_type type}/#{number}"
end

def self.congress_gov_type(bill_type)
Expand All @@ -390,4 +386,4 @@ def self.enacted_as_for(doc)
enacted_as['number'] = enacted_as['number'].to_i
enacted_as
end
end
end

0 comments on commit 52adca5

Please sign in to comment.