Пример #1
0
def migrate_committees(state):

    def attach_members(committee, org):
        for member in committee['members']:
            osid = member.get('leg_id', None)
            person_id = lookup_entry_id('people', osid)
            if person_id:
                m = Membership(person_id, org._id)
                save_object(m)

    spec = {"subcommittee": None}

    if state:
        spec['state'] = state

    for committee in db.committees.find(spec):
        # OK, we need to do the root committees first, so that we have IDs that
        # we can latch onto down below.
        org = Organization(committee['committee'],
                           classification="committee")
        org.parent_id = lookup_entry_id('organizations', committee['state'])
        org.openstates_id = committee['_id']
        org.sources = committee['sources']
        # Look into posts; but we can't be sure.
        save_object(org)
        attach_members(committee, org)

    spec.update({"subcommittee": {"$ne": None}})

    for committee in db.committees.find(spec):
        org = Organization(committee['subcommittee'],
                           classification="committee")

        org.parent_id = lookup_entry_id(
            'organizations',
            committee['parent_id']
        ) or lookup_entry_id(
            'organizations',
            committee['state']
        )

        org.openstates_id = committee['_id']
        org.sources = committee['sources']
        # Look into posts; but we can't be sure.
        save_object(org)
        attach_members(committee, org)
Пример #2
0
def create_or_get_party(what):
    hcid = _hot_cache.get(what, None)
    if hcid:
        return hcid

    org = nudb.organizations.find_one({
        "name": what
    })
    if org:
        _hot_cache[what] = org['_id']
        _cache_touched[what] = True
        return org['_id']

    org = Organization(what, classification="party")
    org.openstates_id = what

    save_object(org)

    _hot_cache[what] = org._id
    _cache_touched[what] = True

    return org._id
Пример #3
0
def migrate_legislatures(state):
    spec = {}
    if state:
        spec['_id'] = state

    for metad in db.metadata.find(spec):
        abbr = metad['abbreviation']
        geoid = "ocd-division/country:us/state:%s" % (abbr)
        cow = Organization(metad['legislature_name'],
                           classification="jurisdiction",
                           geography_id=geoid,
                           abbreviation=abbr)
        cow.openstates_id = abbr

        for post in db.districts.find({"abbr": abbr}):

            cow.add_post(label="Member",
                         role="member",
                         num_seats=post['num_seats'],
                         chamber=post['chamber'],
                         district=post['name'])

        save_object(cow)