Exemplo n.º 1
0
Arquivo: bill.py Projeto: nacyot/pokr
            except Exception, e:
                person = None
                print proposer.encode('utf-8'), e

            person_ids[key] = person.id if person else None

        person_id = person_ids[key]
        if person_id:
            cosponsor_ids.append(person_id)

    set_original, set_current = set(existing_cosponsor_ids), set(cosponsor_ids)
    ids_to_insert = list(set_current - set_original)
    ids_to_delete = list(set_original - set_current)

    if ids_to_insert:
        session.execute(cosponsorship.insert(), [
            {
                'person_id': person_id,
                'bill_id': bill.id,
            } for person_id in ids_to_insert
        ])

    if ids_to_delete:
        session.execute(
            cosponsorship.delete().where(
                and_(cosponsorship.c.person_id.in_(ids_to_delete),
                     cosponsorship.c.bill_id == bill.id)
            )
        )

Exemplo n.º 2
0
            except Exception, e:
                person = None
                print proposer.encode('utf-8'), e

            person_ids[key] = person.id if person else None

        person_id = person_ids[key]

        if person_id and person_id not in existing_cosponsor_ids:
            cosponsorships.append({
                'person_id': person_id,
                'bill_id': bill.id,
            })

    if cosponsorships:
        session.execute(cosponsorship.insert(), cosponsorships)


def insert_reviews(session, bill, reviews_raw):
    reviews = []
    existing_review_names = [r.name for r in bill.reviews]
    for review_name, review_data in reviews_raw.items():
        if review_name in existing_review_names:
            continue

        dates = any_value_with_re(review_data, date_re)
        dates = [datetime.strptime(date_, '%Y-%m-%d').date() for date_ in dates]
        start_date = min(dates) if dates else None
        end_date = max(dates) if dates else None
        reviews.append({
            'name': review_name,