コード例 #1
0
ファイル: test_base.py プロジェクト: AGarrow/pupa
def test_save_related():
    s = Scraper('jurisdiction', '2013', '/tmp/')
    p = Person('Michael Jordan')
    o = Organization('Chicago Bulls')
    p._related.append(o)

    with mock.patch('json.dump') as json_dump:
        s.save_object(p)

    assert_equal(json_dump.mock_calls, [
        mock.call(p.as_dict(), mock.ANY, cls=mock.ANY),
        mock.call(o.as_dict(), mock.ANY, cls=mock.ANY)
    ])
コード例 #2
0
ファイル: __init__.py プロジェクト: AGarrow/pupa
    def get_people(self):
        # committee
        tech = Organization('Technology', classification='committee')
        tech.add_post('Chairman', 'chairman')
        yield tech

        # subcommittee
        ecom = Organization('Subcommittee on E-Commerce',
                            parent=tech,
                            classification='committee')
        yield ecom

        p = Legislator('Paul Tagliamonte', district='6', chamber='upper',
                       party='Independent')
        p.add_committee_membership('Finance')
        p.add_membership(tech, role='chairman')
        yield p
コード例 #3
0
ファイル: convert_openstates.py プロジェクト: AGarrow/pupa
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
コード例 #4
0
ファイル: convert_openstates.py プロジェクト: AGarrow/pupa
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)
コード例 #5
0
ファイル: convert_openstates.py プロジェクト: AGarrow/pupa
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)