Exemple #1
0
def parse_vote_list_file(vote_list_file):
    logging.info("Parsing vote list file...")

    vote_list_info = []

    for vote_list_line in vote_list_file.split("\r\n"):
        if not vote_list_line.strip():
            continue

        vote_info = extract_vote_info_from_parsed_vote_list_line(parse_vote_list_line(vote_list_line))

        vote_info["state"] = get_state_from_icpsr_state_code(vote_info["icpsr_state"]) if vote_info["icpsr_state"] is not None else None
        vote_info["party"] = get_party_from_icpsr_party_code(vote_info["icpsr_party"]) if vote_info["icpsr_party"] is not None else None

        icpsr_id = vote_info["icpsr_id"]

        try:
            bioguide_id = utils.get_person_id("icpsr" if vote_info["state_name"] != "USA" else "icpsr_prez", icpsr_id, "bioguide")
        except KeyError as e:
            logging.error("Problem with member %s ([%d] %s) of %s %s: %s" % (vote_info["member_name"], vote_info["icpsr_party"], vote_info["party"],
                                                                             vote_info["state_name"], vote_info["district"], e.message))
            bioguide_id = None
        else:
            logging.debug("Parsed member %s ([%d] %s) of %s %s..." % (vote_info["member_name"], vote_info["icpsr_party"], vote_info["party"],
                                                                      vote_info["state_name"], vote_info["district"]))

        vote_info["bioguide_id"] = bioguide_id

        # This is used to record the President's position, or something.
        # Mark this record so build_votes can separated it out from Member votes.
        vote_info["is_president"] = True if vote_info["icpsr_state"] == 99 else False

        vote_list_info.append(vote_info)

    return vote_list_info
def parse_vote_list_file(vote_list_file):
    logging.info("Parsing vote list file...")

    vote_list_info = []

    for vote_list_line in vote_list_file.split("\r\n"):
        if not vote_list_line.strip():
            continue

        vote_info = extract_vote_info_from_parsed_vote_list_line(parse_vote_list_line(vote_list_line))

        vote_info["state"] = get_state_from_icpsr_state_code(vote_info["icpsr_state"]) if vote_info["icpsr_state"] is not None else None
        vote_info["party"] = get_party_from_icpsr_party_code(vote_info["icpsr_party"]) if vote_info["icpsr_party"] is not None else None

        icpsr_id = vote_info["icpsr_id"]

        # I think these are mistakes? Don't know if the 9- codes something special.
        if icpsr_id == 91449: icpsr_id = 1449
        if icpsr_id == 92484: icpsr_id = 2484
        if icpsr_id == 94804: icpsr_id = 4804
        if icpsr_id == 94891: icpsr_id = 4891
        if icpsr_id == 96738: icpsr_id = 6738
        if icpsr_id == 98500: icpsr_id = 8500
        if icpsr_id == 99369: icpsr_id = 9369
        if icpsr_id == 90618: icpsr_id = 10618
        if icpsr_id == 90634: icpsr_id = 10634
        if icpsr_id == 91043: icpsr_id = 11043
        if icpsr_id == 93033: icpsr_id = 13033
        if icpsr_id == 94428: icpsr_id = 14428
        if icpsr_id == 94454: icpsr_id = 14454
        if icpsr_id == 94602: icpsr_id = 14602
        if icpsr_id == 94628: icpsr_id = 14628
        if icpsr_id == 95122: icpsr_id = 15122
        if icpsr_id == 95415: icpsr_id = 15415
        if icpsr_id == 3769: icpsr_id = 15101 # guy was given two ids
        if icpsr_id == 14240: icpsr_id = 94240 # per our id

        try:
            bioguide_id = utils.get_person_id("icpsr" if vote_info["state_name"] != "USA" else "icpsr_prez", icpsr_id, "bioguide")
        except KeyError as e:
            # skip some guys named Poe (99999) and Chambers (10509) that don't seem to have existed and didn't cast actual votes,
            # and Jack Swigert (15067) who died before being sworn in.
            # and presidents may not have bioguide IDs
            if icpsr_id not in (99999, 10509, 15067) and vote_info["state_name"] != "USA":
                logging.error("Problem with member %s ([%d] %s) of %s %s: %s" % (vote_info["member_name"], vote_info["icpsr_party"], vote_info["party"],
                                                                             vote_info["state_name"], vote_info["district"], e.message))
                #logging.error(vote_info)
            bioguide_id = None
        else:
            logging.debug("Parsed member %s ([%d] %s) of %s %s..." % (vote_info["member_name"], vote_info["icpsr_party"], vote_info["party"],
                                                                      vote_info["state_name"], vote_info["district"]))
        vote_info["bioguide_id"] = bioguide_id

        # This is used to record the President's position, or something.
        # Mark this record so build_votes can separated it out from Member votes.
        vote_info["is_president"] = True if vote_info["icpsr_state"] == 99 else False

        vote_list_info.append(vote_info)

    return vote_list_info
Exemple #3
0
def get_related_films(person_id):
    statement = text(
        "select * from films where id in (select film_id from relations where person_id = '"
        + get_person_id(person_id)
        + "');"
    )
    return db.execute(statement)
Exemple #4
0
def parse_vote_list_file(vote_list_file):
    logging.info("Parsing vote list file...")

    vote_list_info = []

    for vote_list_line in vote_list_file.split("\r\n"):
        if not vote_list_line.strip():
            continue

        vote_info = extract_vote_info_from_parsed_vote_list_line(
            parse_vote_list_line(vote_list_line))

        vote_info["state"] = get_state_from_icpsr_state_code(
            vote_info["icpsr_state"]
        ) if vote_info["icpsr_state"] is not None else None
        vote_info["party"] = get_party_from_icpsr_party_code(
            vote_info["icpsr_party"]
        ) if vote_info["icpsr_party"] is not None else None

        icpsr_id = vote_info["icpsr_id"]

        try:
            bioguide_id = utils.get_person_id(
                "icpsr" if vote_info["state_name"] != "USA" else "icpsr_prez",
                icpsr_id, "bioguide")
        except KeyError as e:
            logging.error("Problem with member %s ([%d] %s) of %s %s: %s" %
                          (vote_info["member_name"], vote_info["icpsr_party"],
                           vote_info["party"], vote_info["state_name"],
                           vote_info["district"], e.message))
            bioguide_id = None
        else:
            logging.debug("Parsed member %s ([%d] %s) of %s %s..." %
                          (vote_info["member_name"], vote_info["icpsr_party"],
                           vote_info["party"], vote_info["state_name"],
                           vote_info["district"]))

        vote_info["bioguide_id"] = bioguide_id

        # This is used to record the President's position, or something.
        # Mark this record so build_votes can separated it out from Member votes.
        vote_info[
            "is_president"] = True if vote_info["icpsr_state"] == 99 else False

        vote_list_info.append(vote_info)

    return vote_list_info
Exemple #5
0
def parse_vote_list_file(vote_list_file):
    logging.info("Parsing vote list file...")

    vote_list_info = []

    for vote_list_line in vote_list_file.split("\r\n"):
        if not vote_list_line.strip():
            continue

        vote_info = extract_vote_info_from_parsed_vote_list_line(
            parse_vote_list_line(vote_list_line))

        vote_info["state"] = get_state_from_icpsr_state_code(
            vote_info["icpsr_state"]
        ) if vote_info["icpsr_state"] is not None else None
        vote_info["party"] = get_party_from_icpsr_party_code(
            vote_info["icpsr_party"]
        ) if vote_info["icpsr_party"] is not None else None

        icpsr_id = vote_info["icpsr_id"]

        # I think these are mistakes? Don't know if the 9- codes something special.
        if icpsr_id == 91449: icpsr_id = 1449
        if icpsr_id == 92484: icpsr_id = 2484
        if icpsr_id == 94804: icpsr_id = 4804
        if icpsr_id == 94891: icpsr_id = 4891
        if icpsr_id == 96738: icpsr_id = 6738
        if icpsr_id == 98500: icpsr_id = 8500
        if icpsr_id == 99369: icpsr_id = 9369
        if icpsr_id == 90618: icpsr_id = 10618
        if icpsr_id == 90634: icpsr_id = 10634
        if icpsr_id == 91043: icpsr_id = 11043
        if icpsr_id == 93033: icpsr_id = 13033
        if icpsr_id == 94428: icpsr_id = 14428
        if icpsr_id == 94454: icpsr_id = 14454
        if icpsr_id == 94602: icpsr_id = 14602
        if icpsr_id == 94628: icpsr_id = 14628
        if icpsr_id == 95122: icpsr_id = 15122
        if icpsr_id == 95415: icpsr_id = 15415
        if icpsr_id == 3769: icpsr_id = 15101  # guy was given two ids
        if icpsr_id == 14240: icpsr_id = 94240  # per our id

        try:
            bioguide_id = utils.get_person_id(
                "icpsr" if vote_info["state_name"] != "USA" else "icpsr_prez",
                icpsr_id, "bioguide")
        except KeyError as e:
            # skip some guys named Poe (99999) and Chambers (10509) that don't seem to have existed and didn't cast actual votes,
            # and Jack Swigert (15067) who died before being sworn in.
            # and presidents may not have bioguide IDs
            if icpsr_id not in (99999, 10509,
                                15067) and vote_info["state_name"] != "USA":
                logging.error(
                    "Problem with member %s ([%d] %s) of %s %s: %s" %
                    (vote_info["member_name"], vote_info["icpsr_party"],
                     vote_info["party"], vote_info["state_name"],
                     vote_info["district"], e.message))
                #logging.error(vote_info)
            bioguide_id = None
        else:
            logging.debug("Parsed member %s ([%d] %s) of %s %s..." %
                          (vote_info["member_name"], vote_info["icpsr_party"],
                           vote_info["party"], vote_info["state_name"],
                           vote_info["district"]))
        vote_info["bioguide_id"] = bioguide_id

        # This is used to record the President's position, or something.
        # Mark this record so build_votes can separated it out from Member votes.
        vote_info[
            "is_president"] = True if vote_info["icpsr_state"] == 99 else False

        vote_list_info.append(vote_info)

    return vote_list_info
Exemple #6
0
def get_person_by_id(id):
    statement = text("select * from people where id = '" + get_person_id(id) +
                     "';")
    return db.execute(statement)