Exemplo n.º 1
0
def load_committees(bill_dict):
    """Load committees from data files into database using parse.py"""

    print "Committees"

    db_not_empty = Committee.query.filter_by(committee_id=1).first()

    bill_number = parse.get_bill_number(bill_dict).get('bill_number')
    bill_type = parse.get_bill_type(bill_dict).get('bill_type')
    bill_id = bill_type + '-' + bill_number

    for item in parse.get_committee(bill_dict).keys():
        committee_name = parse.get_committee(bill_dict).get(item)
        if committee_name == None:
            pass
        else:
            committee = Committee(name=committee_name)
            if not db_not_empty:  #if db is empty
                db.session.add(committee)
                db.session.commit()
            elif Committee.query.filter_by(name=committee_name).first():
                pass
            else:
                db.session.add(committee)
                db.session.commit()
            # import pdb; pdb.set_trace()
            # committee = Committee(name=committee_name)
            # db.session.add(committee)
            # db.session.commit()

            committees = Committee.query.filter_by(name=committee_name).first()
            bill_committee = BillCommittee(
                bill_id=bill_id, committee_id=committees.committee_id)
            db.session.add(bill_committee)
            db.session.commit()
Exemplo n.º 2
0
def load_sponsorships(bill_dict):
    """Load sponsorships from data files into database using parse.py"""

    print "Sponsorships"

    bill_number = parse.get_bill_number(bill_dict).get('bill_number')
    bill_type = parse.get_bill_type(bill_dict).get('bill_type')
    bill_id = bill_type + '-' + bill_number

    if not parse.get_sponsor_info(bill_dict):

        with open('cosponsors.json', 'r') as f:
            for line in f:

                line = json.loads(line)
                name = line.keys()[0]
                #fix capitaliztion and redundancy in senator table
                date = line.get(name).get('withdraw_date')
                name = name.title()
                senator = Senator.query.filter_by(name=name).first()

                if not date:
                    withdrawn = False
                    withdrawn_date = None
                else:
                    withdrawn_date = datetime.datetime.strptime(
                        date, "%Y-%m-%d")
                    withdrawn = True

                sponsorship = Sponsorship(bill_id=bill_id,
                                          senator_id=senator.senator_id,
                                          withdrawn=withdrawn,
                                          withdrawn_date=withdrawn_date)

                db.session.add(sponsorship)
                db.session.commit()

    else:
        withdrawn = False
        withdrawn_date = None

        name = parse.get_sponsor_info(bill_dict).keys()[0]

        senator = Senator.query.filter_by(name=name).first()

        sponsorship = Sponsorship(bill_id=bill_id,
                                  senator_id=senator.senator_id,
                                  withdrawn=withdrawn,
                                  withdrawn_date=withdrawn_date)

        db.session.add(sponsorship)
        db.session.commit()
Exemplo n.º 3
0
def load_actions(bill_dict):
    """Load actions from data files into database using parse.py"""

    print "Actions"

    bill_number = parse.get_bill_number(bill_dict).get('bill_number')
    bill_type = parse.get_bill_type(bill_dict).get('bill_type')
    bill_id = bill_type + '-' + bill_number

    for item in parse.get_action_taken(bill_dict).get('action'):

        action_date = item[0]
        date = datetime.datetime.strptime(action_date, "%Y-%m-%d")
        action_text = item[1]

        action = Action(bill_id=bill_id, action_text=action_text, date=date)
        db.session.add(action)

    db.session.commit()
Exemplo n.º 4
0
def load_bills(bill_dict):
    """Load bills from data files into database using parse.py"""

    bill_number = str(parse.get_bill_number(bill_dict).get('bill_number'))
    bill_type = parse.get_bill_type(bill_dict).get('bill_type')
    title = parse.get_bill_title(bill_dict).get('bill_title')
    bill_date = parse.get_date_introduced(bill_dict).get('date_introduced')
    description = parse.get_bill_summary(bill_dict).get('bill_summary')

    date = datetime.datetime.strptime(bill_date, "%Y-%m-%d")

    bill = Bill(bill_id=bill_type + '-' + bill_number,
                title=title,
                date=date,
                description=description,
                bill_type=bill_type)

    # adds bill to session so we can store it
    db.session.add(bill)

    # commits bill info to DB
    db.session.commit()
Exemplo n.º 5
0
def load_tags(bill_dict):
    """Load tags from data files into database using parse.py"""

    print "Tags"

    db_not_empty = Tag.query.filter_by(tag_id=1).first()

    bill_tags = parse.get_bill_info(bill_dict)
    bill_number = parse.get_bill_number(bill_dict).get('bill_number')
    bill_type = parse.get_bill_type(bill_dict).get('bill_type')
    bill_id = bill_type + '-' + bill_number

    for key in bill_tags:

        if bill_tags.get(key):
            for item in bill_tags.get(key):
                if item == None:
                    pass
                else:
                    tag_text = item[0]
                    tag = Tag(tag_text=tag_text)

                    if not db_not_empty:  #if db is empty
                        db.session.add(tag)
                        db.session.commit()
                    elif Tag.query.filter_by(tag_text=tag_text).first():
                        pass
                    else:
                        db.session.add(tag)
                        db.session.commit()

                    tags = Tag.query.filter_by(tag_text=tag_text).first()
                    bill_tag_item = BillTag(bill_id=bill_id,
                                            tag_id=tags.tag_id)
                    db.session.add(bill_tag_item)
                    db.session.commit()