Пример #1
0
def create_vote_from_html_row(row, bill):
    ncol = 0
    details = ''
    decision = ''

    for column in row.iter():
        if column.tag == 'td':
            ncol += 1

        if ncol == 1 and column.tag == 'a':
            party_name = column.text
            print(party_name)
        elif ncol == 2:
            number_of_seats = int(column.text)
            print(number_of_seats)
        elif ncol == 3 and column.tag == 'img':
            decision = Vote.FOR
        elif ncol == 4 and column.tag == 'img':
            decision = Vote.AGAINST
        elif ncol == 5 and column.tag == 'h4':
            details = column.text
            print(details)

    party = PoliticalParty.get_party(party_name)
    vote = Vote.objects.create(bill=bill, party=party, number_of_seats=number_of_seats,
                               decision=decision, details=details)
    vote.save()
    return vote
Пример #2
0
def create_members():
    url = 'http://www.tweedekamer.nl/kamerleden/alle_kamerleden'
    page = requests.get(url)
    tree = lxml.html.fromstring(page.content)

    parliament = get_or_create_tweede_kamer()

    rows = tree.xpath("//tbody/tr")

    for row in rows:
        columns = row.xpath("td")
        if len(columns) == 8:
            surname = columns[0][0].text.split(',')[0]
            print(surname)
            prefix = columns[0][0].text.split('.')[-1].strip()
            forename = columns[1][0].text
            if Person.person_exists(forename, surname):
                person = Person.objects.get(forename=forename, surname=surname)
            else:
                person = Person.objects.create(
                    forename=forename,
                    surname=surname,
                    surname_prefix=prefix,
                )
            party_name = columns[2][0].text
            party = PoliticalParty.get_party(party_name)
            # residence = columns[3][0].text
            # age = columns[4][0][0].text
            # sex = columns[5][0].text
            # assert age is not None
            # if sex == 'Man':
            #     sex = Member.MALE
            # elif sex == 'Vrouw':
            #     sex = Member.FEMALE
            party_member = PartyMember.objects.create(person=person, party=party)
            parliament_member = ParliamentMember.objects.create(person=person, parliament=parliament)
            print("new person: " + str(person))
            print("new party member: " + str(party_member))
            print("new parliament member: " + str(parliament_member))