def import_bills(state, data_dir): data_dir = os.path.join(data_dir, state) pattern = os.path.join(data_dir, "bills", "*.json") for path in glob.iglob(pattern): with open(path) as f: data = prepare_obj(json.load(f)) bill = db.bills.find_one( {"state": data["state"], "session": data["session"], "chamber": data["chamber"], "bill_id": data["bill_id"]} ) for sponsor in data["sponsors"]: id = get_legislator_id(state, data["session"], None, sponsor["name"]) sponsor["leg_id"] = id for vote in data["votes"]: for vtype in ("yes_votes", "no_votes", "other_votes"): svlist = [] for svote in vote[vtype]: id = get_legislator_id(state, data["session"], vote["chamber"], svote) svlist.append({"name": svote, "leg_id": id}) vote[vtype] = svlist if not bill: data["created_at"] = datetime.datetime.now() data["updated_at"] = data["created_at"] data["keywords"] = list(keywordize(data["title"])) insert_with_id(data) else: data["keywords"] = list(keywordize(data["title"])) update(bill, data, db.bills)
def bill_keywords(bill): """ Get the keyword set for all of a bill's titles. """ keywords = keywordize(bill['title']) for title in bill['alternate_titles']: keywords = keywords.union(keywordize(title)) return keywords