Exemplo n.º 1
0
    def migrate_legislatures(self, state):
        spec = {}
        if state:
            spec['_id'] = state

        for metad in self.billy_db.metadata.find(spec, timeout=False):
            abbr = metad['abbreviation']
            geoid = "ocd-division/country:us/state:%s" % (abbr)
            for chamber in metad['chambers']:
                cn = metad['chambers'][chamber]['name']
                cow = Organization("%s, %s" % (metad['legislature_name'], cn),
                                   classification="legislature",
                                   chamber=chamber,
                                   division_id=geoid,
                                   abbreviation=abbr)
                cow._openstates_id = "%s-%s" % (abbr, chamber)
                cow.add_source(metad['legislature_url'])

                for post in self.billy_db.districts.find({"abbr": abbr}):
                    if post['chamber'] != chamber:
                        continue

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

                self.save_object(cow)

            meta = self.billy_db.metadata.find_one({"_id": cow.abbreviation})
            if meta is None:
                raise Exception
            meta.pop("_id")
            meta['_id'] = cow.jurisdiction_id

            for badtag in ["latest_json_url", "latest_json_date",
                           "latest_csv_url", "latest_csv_date"]:
                meta.pop(badtag, None)

            meta['division_id'] = "ocd-division/country:us/state:%s" % (
                cow.abbreviation
            )

            db.jurisdictions.save(meta)
Exemplo n.º 2
0
    def migrate_committees(self, state):

        def attach_members(committee, org):
            term = get_current_term(obj_to_jid(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,
                                   role=member['role'],
                                   chamber=org.chamber,
                                   # term=term['name'],
                                   start_date=str(term['start_year']))
                    m.add_extra('term', term['name'])
                    # We can assume there's no end_year because it's a current
                    # member of the committee. If they left the committee, we don't
                    # know about it yet :)
                    self.save_object(m)

                    if m.role != 'member':
                        # In addition to being the (chair|vice-chair),
                        # they should also be noted as a member.
                        m = Membership(person_id, org._id,
                                       role='member',
                                       chamber=org.chamber,
                                       start_date=str(term['start_year']))
                        m.add_extra('term', term['name'])
                        self.save_object(m)

        spec = {"subcommittee": None}

        if state:
            spec['state'] = state

        for committee in self.billy_db.committees.find(spec, timeout=False):
            # 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.chamber = committee['chamber']
            org.parent_id = lookup_entry_id('organizations', committee['state'])
            org.identifiers = [{'scheme': 'openstates',
                                'identifier': committee['_id']}]
            org._openstates_id = committee['_id']
            org.sources = committee['sources']
            org.created_at = committee['created_at']
            org.updated_at = committee['updated_at']
            # Look into posts; but we can't be sure.
            self.save_object(org)
            attach_members(committee, org)

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

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

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

            org.identifiers = [{'scheme': 'openstates',
                               'identifier': committee['_id']}]
            org._openstates_id = committee['_id']
            org.sources = committee['sources']
            org.chamber = committee['chamber']
            # Look into posts; but we can't be sure.
            self.save_object(org)
            attach_members(committee, org)