Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add committee leadership positions #317

Merged
merged 1 commit into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions server_py/flatgov/bills/migrations/0002_cosponsor_leadership.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1.8 on 2021-04-16 15:34

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('bills', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='cosponsor',
name='leadership',
field=models.JSONField(blank=True, default=list, null=True),
),
]
1 change: 1 addition & 0 deletions server_py/flatgov/bills/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class Cosponsor(models.Model):
party = models.CharField(max_length=100, blank=True, null=True)
state = models.CharField(max_length=2, blank=True, null=True)
type = models.CharField(max_length=3, blank=True, null=True)
leadership = models.JSONField(default=list, blank=True, null=True) #list of terms in Leadership, with position; not everyone will have this item
terms = models.JSONField(default=list)
committees = models.JSONField(default=list, blank=True, null=True) #list of objects of the form {'thomas_id':x, 'rank':x, 'party': x}

Expand Down
91 changes: 76 additions & 15 deletions server_py/flatgov/common/cosponsor.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,55 @@ def updateLegislators():
'district': 13,
'party': 'Democrat'},
...]}

LEADERSHIP SAMPLE:
- id:
bioguide: P000197
thomas: '00905'
govtrack: 400314
opensecrets: N00007360
votesmart: 26732
icpsr: 15448
fec:
- H8CA05035
cspan: 6153
wikipedia: Nancy Pelosi
house_history: 19519
ballotpedia: Nancy Pelosi
maplight: 408
wikidata: Q170581
google_entity_id: kg:/m/012v1t
name:
first: Nancy
last: Pelosi
official_full: Nancy Pelosi
bio:
birthday: '1940-03-26'
gender: F
leadership_roles:
- title: House Minority Leader
chamber: house
start: '2011-01-05'
end: '2013-01-03'
- title: House Minority Leader
chamber: house
start: '2013-01-03'
end: '2015-01-03'
- title: House Minority Leader
chamber: house
start: '2015-01-06'
end: '2017-01-03'
- title: House Minority Leader
chamber: house
start: '2017-01-03'
end: '2019-01-03'
- title: Speaker of the House
chamber: house
start: '2019-01-03'
end: '2021-01-03'
- title: Speaker of the House
chamber: house
start: '2021-01-03'
"""
legislatorids = getAndParseYAML(LEGISLATORS_URL)
for legislator in legislatorids:
Expand All @@ -72,27 +121,39 @@ def updateLegislators():
type = ""
party = ""
state = ""
leadership = legislator.get('leadership_roles', [])
updateData = {'name_first': name_first,
'name_last': name_last,
'bioguide_id': legislatorid.get("bioguide", ""),
'thomas': legislatorid.get("thomas", ""),
'party': party,
'state': state,
'type': type,
'terms': terms,
}
if leadership:
#print('{0}\n'.format(full_official))
#print(leadership)
# Reorder so that most current is first
reversed(leadership)
updateData['leadership'] = leadership
#else:
# print('No leadership roles for: {0}\n'.format(full_official))


print('Updating legislator: {0}'.format(full_official))
Cosponsor.objects.update_or_create(name=name,
name_full_official=full_official,
defaults={
'name_first': name_first,
'name_last': name_last,
'bioguide_id': legislatorid.get("bioguide", ""),
'thomas': legislatorid.get("thomas", ""),
'party': party,
'state': state,
'type': type,
'terms': terms,
}
defaults=updateData
)

def updateCommittees():
"""
Add committee data to database.
Download and parse YAML for committees, then add or update fields.
*** SAMPLE ***
add committee data to database.
download and parse yaml for committees, then add or update fields.
*** sample ***
{'type': 'house',
'name': 'House Committee on Agriculture',
'name': 'house committee on agriculture',
'url': 'https://agriculture.house.gov/',
'minority_url': 'https://republicans-agriculture.house.gov',
'thomas_id': 'HSAG',
Expand Down Expand Up @@ -193,7 +254,7 @@ def updateCommitteeMembers():
"""
committee_membership = getAndParseYAML(COMMITTEE_MEMBERSHIP_URL)
for committee_thomas_id, cosponsor_items in committee_membership.items():
#print(committee_thomas_id)
print('Committee id: {0}'.format(committee_thomas_id))
try:
committee_item = Committee.objects.get(thomas_id=committee_thomas_id)
except Exception as err:
Expand Down