Exemplo n.º 1
0
def insert_person(session, election_type, assembly_id, r):
    person = guess_person(r)

    if person:
        extra_vars = json.loads(person.extra_vars)
        extra_vars.update(r)
        extra_vars[election_type][assembly_id] = r
        person.extra_vars = json.dumps(extra_vars)

    else:
        person_id = get_person_id(r)
        name_en = translit(r['name_kr'], 'ko', 'en', 'name')
        gender = map_gender[r['sex']]
        birthday = '%04d%02d%02d' % (
                int(r.get('birthyear', 0)),
                int(r.get('birthmonth', 0)),
                int(r.get('birthday', 0))
                )
        education = markup(r['education'], 'education') if 'education' in r else []
        address = markup(r['address'], 'district') if 'address' in r else []
        extra_vars = r.copy()
        # FIXME: THIS_ASSEMBLY를 쓰면 시점을 제대로 못잡음
        extra_vars['assembly'] = {}
        extra_vars['assembly'][THIS_ASSEMBLY] = r

        person = Person(
                id=person_id,
                name=r['name_kr'],
                name_en=name_en,
                name_cn=r['name_cn'],
                gender=gender,
                birthday=birthday,
                education=[term[0] for term in education],
                education_id=[term[1] for term in education],
                address=[term[0] for term in address],
                address_id=[term[1] for term in address],
                image=r.get('image', None),
                twitter=r.get('twitter', None),
                facebook=r.get('facebook', None),
                blog=r.get('blog', None),
                homepage=r.get('homepage', None),
                extra_vars=json.dumps(extra_vars)
                )

        session.add(person)
        session.flush()

    return person.id
Exemplo n.º 2
0
def insert_person(session, election_type, assembly_id, r):
    person = guess_person(r)

    if person:
        extra_vars = json.loads(person.extra_vars)
        extra_vars.update(r)
        extra_vars[election_type][assembly_id] = r
        person.extra_vars = json.dumps(extra_vars)

    else:
        person_id = get_person_id(r)
        name_en = translit(r['name_kr'], 'ko', 'en', 'name')
        gender = map_gender[r['sex']]
        birthday = '%04d%02d%02d' % (int(r.get(
            'birthyear', 0)), int(r.get('birthmonth',
                                        0)), int(r.get('birthday', 0)))
        education = markup(r['education'],
                           'education') if 'education' in r else []
        address = markup(r['address'], 'district') if 'address' in r else []
        extra_vars = r.copy()
        # FIXME: THIS_ASSEMBLY를 쓰면 시점을 제대로 못잡음
        extra_vars['assembly'] = {}
        extra_vars['assembly'][THIS_ASSEMBLY] = r

        person = Person(id=person_id,
                        name=r['name_kr'],
                        name_en=name_en,
                        name_cn=r['name_cn'],
                        gender=gender,
                        birthday=birthday,
                        education=[term[0] for term in education],
                        education_id=[term[1] for term in education],
                        address=[term[0] for term in address],
                        address_id=[term[1] for term in address],
                        image=r.get('image', None),
                        twitter=r.get('twitter', None),
                        facebook=r.get('facebook', None),
                        blog=r.get('blog', None),
                        homepage=r.get('homepage', None),
                        extra_vars=json.dumps(extra_vars))

        session.add(person)
        session.flush()

    return person.id
Exemplo n.º 3
0
def insert_candidacy(session, r, person_id, date):
    election_id = get_election_id(session, date)
    party_id = get_party(session, r['party']).id
    district = markup(r['district'], 'district')
    candidacy = Candidacy(
            person_id=person_id,
            election_id=election_id,
            party_id=party_id,
            is_elected=r['elected'],
            cand_no=to_int(r.get('cand_no', 0)),
            vote_score=to_int(r.get('votenum', 0)),
            vote_share=to_float(r.get('voterate', 0)),
            district=[term[0] for term in district],
            district_id=[term[1] for term in district],
            )
    session.add(candidacy)
Exemplo n.º 4
0
def insert_candidacy(session, r, person_id, date):
    election_id = get_election_id(session, date)
    party_id = get_party(session, r['party']).id
    district = markup(r['district'], 'district')
    candidacy = Candidacy(
        person_id=person_id,
        election_id=election_id,
        party_id=party_id,
        is_elected=r['elected'],
        cand_no=to_int(r.get('cand_no', 0)),
        vote_score=to_int(r.get('votenum', 0)),
        vote_share=to_float(r.get('voterate', 0)),
        district=[term[0] for term in district],
        district_id=[term[1] for term in district],
    )
    session.add(candidacy)