Skip to content

Commit

Permalink
to_mongo --clear-old-roles & offices
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesturk committed Oct 20, 2018
1 parent 0a7c347 commit d1753a6
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions scripts/to_mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def get_next_id(db, abbr):
return f'{abbr.upper()}L{new_id:06d}'


def dir_to_mongo(abbr, create, verbose):
def dir_to_mongo(abbr, create, clear_old_roles, verbose):
db = pymongo.MongoClient(os.environ.get('BILLY_MONGO_HOST', 'localhost'))['fiftystates']

metadata = db.metadata.find({'_id': abbr})[0]
Expand Down Expand Up @@ -83,7 +83,8 @@ def dir_to_mongo(abbr, create, verbose):
try:
old_person = db.legislators.find({'_id': legacy_ids[0]})[0]
created_at = old_person['created_at']
old_roles = old_person.get('old_roles', {})
if not clear_old_roles:
old_roles = old_person.get('old_roles', {})
except IndexError:
pass

Expand All @@ -102,6 +103,7 @@ def dir_to_mongo(abbr, create, verbose):
'party': party,
'email': email,
'url': url,
'offices': offices,
'created_at': created_at,

'first_name': first_name,
Expand Down Expand Up @@ -152,8 +154,9 @@ def retire_person(db, leg):
@click.command()
@click.argument('abbreviations', nargs=-1)
@click.option('--create/--no-create', default=False)
@click.option('--clear-old-roles/--no-clear-old-roles', default=False)
@click.option('-v', '--verbose', count=True)
def to_database(abbreviations, create, verbose):
def to_database(abbreviations, create, verbose, clear_old_roles):
"""
Sync YAML files to legacy MongoDB.
"""
Expand All @@ -163,7 +166,7 @@ def to_database(abbreviations, create, verbose):

for abbr in abbreviations:
click.secho('==== {} ===='.format(abbr), bold=True)
dir_to_mongo(abbr, create, verbose)
dir_to_mongo(abbr, create, clear_old_roles, verbose)


if __name__ == '__main__':
Expand Down

0 comments on commit d1753a6

Please sign in to comment.