Example #1
0
def do_import(juris, args):
    # import inside here because to avoid loading Django code unnecessarily
    from openstates.importers import (
        JurisdictionImporter,
        BillImporter,
        VoteEventImporter,
    )

    datadir = os.path.join(settings.SCRAPED_DATA_DIR, args.module)

    juris_importer = JurisdictionImporter(juris.jurisdiction_id)
    bill_importer = BillImporter(juris.jurisdiction_id)
    vote_event_importer = VoteEventImporter(juris.jurisdiction_id,
                                            bill_importer)
    report = {}

    with transaction.atomic():
        print("import jurisdictions...")
        report.update(juris_importer.import_directory(datadir))
        if settings.ENABLE_BILLS:
            print("import bills...")
            report.update(bill_importer.import_directory(datadir))
        if settings.ENABLE_VOTES:
            print("import vote events...")
            report.update(vote_event_importer.import_directory(datadir))

    # compile info on all sessions that were updated in this run
    seen_sessions = set()
    seen_sessions.update(bill_importer.get_seen_sessions())
    seen_sessions.update(vote_event_importer.get_seen_sessions())
    for session in seen_sessions:
        generate_session_report(session)

    return report
Example #2
0
def do_import(juris: State, args: argparse.Namespace) -> dict[str, typing.Any]:
    # import inside here because to avoid loading Django code unnecessarily
    from openstates.importers import (
        JurisdictionImporter,
        BillImporter,
        VoteEventImporter,
        EventImporter,
    )
    from openstates.data.models import Jurisdiction as DatabaseJurisdiction

    datadir = os.path.join(settings.SCRAPED_DATA_DIR, args.module)

    juris_importer = JurisdictionImporter(juris.jurisdiction_id)
    bill_importer = BillImporter(juris.jurisdiction_id)
    vote_event_importer = VoteEventImporter(juris.jurisdiction_id,
                                            bill_importer)
    event_importer = EventImporter(juris.jurisdiction_id, vote_event_importer)
    report = {}

    with transaction.atomic():
        print("import jurisdictions...")
        report.update(juris_importer.import_directory(datadir))
        print("import bills...")
        report.update(bill_importer.import_directory(datadir))
        print("import vote events...")
        report.update(vote_event_importer.import_directory(datadir))
        print("import events...")
        report.update(event_importer.import_directory(datadir))
        DatabaseJurisdiction.objects.filter(id=juris.jurisdiction_id).update(
            latest_bill_update=datetime.datetime.utcnow())

    # compile info on all sessions that were updated in this run
    seen_sessions = set()
    seen_sessions.update(bill_importer.get_seen_sessions())
    seen_sessions.update(vote_event_importer.get_seen_sessions())
    for session in seen_sessions:
        generate_session_report(session)

    return report
Example #3
0
def do_import(juris, args):
    # import inside here because to avoid loading Django code unnecessarily
    from openstates.importers import (
        JurisdictionImporter,
        OrganizationImporter,
        PersonImporter,
        PostImporter,
        MembershipImporter,
        BillImporter,
        VoteEventImporter,
        EventImporter,
    )

    datadir = os.path.join(settings.SCRAPED_DATA_DIR, args.module)

    juris_importer = JurisdictionImporter(juris.jurisdiction_id)
    org_importer = OrganizationImporter(juris.jurisdiction_id)
    person_importer = PersonImporter(juris.jurisdiction_id)
    post_importer = PostImporter(juris.jurisdiction_id, org_importer)
    membership_importer = MembershipImporter(
        juris.jurisdiction_id, person_importer, org_importer, post_importer
    )
    bill_importer = BillImporter(juris.jurisdiction_id, org_importer, person_importer)
    vote_event_importer = VoteEventImporter(
        juris.jurisdiction_id, person_importer, org_importer, bill_importer
    )
    event_importer = EventImporter(
        juris.jurisdiction_id,
        org_importer,
        person_importer,
        bill_importer,
        vote_event_importer,
    )

    report = {}

    with transaction.atomic():
        print("import jurisdictions...")
        report.update(juris_importer.import_directory(datadir))
        if settings.ENABLE_PEOPLE_AND_ORGS:
            print("import organizations...")
            report.update(org_importer.import_directory(datadir))
            print("import people...")
            report.update(person_importer.import_directory(datadir))
            print("import posts...")
            report.update(post_importer.import_directory(datadir))
            print("import memberships...")
            report.update(membership_importer.import_directory(datadir))
        if settings.ENABLE_BILLS:
            print("import bills...")
            report.update(bill_importer.import_directory(datadir))
        if settings.ENABLE_EVENTS:
            print("import events...")
            report.update(event_importer.import_directory(datadir))
        if settings.ENABLE_VOTES:
            print("import vote events...")
            report.update(vote_event_importer.import_directory(datadir))

    # compile info on all sessions that were updated in this run
    seen_sessions = set()
    seen_sessions.update(bill_importer.get_seen_sessions())
    seen_sessions.update(vote_event_importer.get_seen_sessions())
    for session in seen_sessions:
        generate_session_report(session)

    return report