def test_find_party_dash(self): party_expected = PoliticalParty.objects.create( name='Vrijzinnig Democratische Bond', name_short='VDB') party = PoliticalParty.find_party('Vrijzinnig Democratische Bond') self.assertEqual(party, party_expected) party = PoliticalParty.find_party('Vrijzinnig-Democratische Bond') self.assertEqual(party, party_expected)
def test_create_kuzu(self): person_wikidata_id = 'Q616635' # Tunahan Kuzu parliament = Parliament.get_or_create_tweede_kamer() members = openkamer.parliament.create_parliament_member_from_wikidata_id(parliament, person_wikidata_id) self.assertEqual(len(members), 3) party_expected_0 = PoliticalParty.find_party('PvdA') party_expected_1 = PoliticalParty.find_party('GrKÖ') party_expected_2 = PoliticalParty.find_party('DENK') self.assertEqual(members[0].party, party_expected_0) self.assertEqual(members[1].party, party_expected_1) self.assertEqual(members[2].party, party_expected_2)
def test_create_parliament_member_from_wikidata_kuzu(self): person_wikidata_id = 'Q616635' # Tunahan Kuzu parliament = Parliament.get_or_create_tweede_kamer() members = openkamer.parliament.create_parliament_member_from_wikidata_id( parliament, person_wikidata_id) self.assertEqual(len(members), 3) party_expected_0 = PoliticalParty.find_party('PvdA') party_expected_1 = PoliticalParty.find_party('GrKÖ') party_expected_2 = PoliticalParty.find_party('DENK') self.assertEqual(members[0].party, party_expected_0) self.assertEqual(members[1].party, party_expected_1) self.assertEqual(members[2].party, party_expected_2)
def create_parliament_member_from_wikidata_id(parliament, person_wikidata_id): wikidata_item = wikidata.WikidataItem(person_wikidata_id) person = get_or_create_person(person_wikidata_id, wikidata_item=wikidata_item, add_initials=True) logger.info(person) positions = wikidata_item.get_parliament_positions_held() members = [] for position in positions: parliament_member = ParliamentMember.objects.create( person=person, parliament=parliament, joined=position['start_time'], left=position['end_time']) logger.info(parliament_member) members.append(parliament_member) if position['part_of_id']: party_item = wikidata.WikidataItem(position['part_of_id']) parties = PoliticalParty.objects.filter( wikidata_id=position['part_of_id']) if parties: party = parties[0] else: party = PoliticalParty.find_party( party_item.get_label(language='nl')) if not party: party = create_party_wikidata( wikidata_id=position['part_of_id']) PartyMember.objects.create(person=person, party=party, joined=position['start_time'], left=position['end_time']) return members
def create_party(name, name_short): party = PoliticalParty.find_party(name) if party: party.delete() party = PoliticalParty.objects.create(name=name, name_short=name_short) party.update_info(language='nl') return party
def create_parliament_member_from_wikidata_id(parliament, person_wikidata_id): wikidata_item = wikidata.WikidataItem(person_wikidata_id) person = get_or_create_person(person_wikidata_id, wikidata_item=wikidata_item, add_initials=True) logger.info(person) positions = wikidata_item.get_parliament_positions_held() members = [] for position in positions: parliament_member = ParliamentMember.objects.create( person=person, parliament=parliament, joined=position['start_time'], left=position['end_time'] ) logger.info(parliament_member) members.append(parliament_member) if position['part_of_id']: party_item = wikidata.WikidataItem(position['part_of_id']) parties = PoliticalParty.objects.filter(wikidata_id=position['part_of_id']) if parties: party = parties[0] else: party = PoliticalParty.find_party(party_item.get_label(language='nl')) if not party: party = create_party_wikidata(wikidata_id=position['part_of_id']) PartyMember.objects.create(person=person, party=party, joined=position['start_time'], left=position['end_time']) return members
def create_votes_party(voting, votes): logger.info('BEGIN') for vote in votes: party = PoliticalParty.find_party(vote.party_name) if not party: wikidata_id = wikidata.search_political_party_id(vote.party_name, language='nl') name = vote.party_name if wikidata_id: item = wikidata.WikidataItem(wikidata_id) name = item.get_label('nl') if not name: logger.error('vote party has no name') assert False party = PoliticalParty.objects.create(name=name, name_short=vote.party_name, wikidata_id=wikidata_id) party.update_info(language='nl') if not vote.decision: logger.warning('vote has no decision, vote.details: ' + str(vote.details)) VoteParty.objects.create(voting=voting, party=party, party_name=vote.party_name, number_of_seats=vote.number_of_seats, decision=get_decision(vote.decision), details=vote.details, is_mistake=vote.is_mistake) logger.info('END')
def create_parties(): url = 'https://www.tweedekamer.nl/kamerleden/fracties' page = requests.get(url) tree = lxml.html.fromstring(page.content) rows = tree.xpath("//ul[@class='reset grouped-list']/li/a") for row in rows: columns = row.text.split('-') if len(columns) > 1: name = columns[0].strip() name_short = columns[1] name_short = re.sub(r'\(.+?\)', '', name_short).strip() else: name = columns[0] name = re.sub(r'\(.+?\)', '', name).strip() name_short = name # print('name: ' + name) # print('short: ' + name_short) if PoliticalParty.find_party(name): print('WARNING: party already exists!') else: party = PoliticalParty.objects.create(name=name, name_short=name_short) party.update_info('nl', 'nl') party.save() print('created: ' + str(party))
def test_create_martin(self): person_wikidata_id = 'Q2801440' # Martin van Rooijen parliament = Parliament.get_or_create_tweede_kamer() members = openkamer.parliament.create_parliament_member_from_wikidata_id(parliament, person_wikidata_id) self.assertEqual(len(members), 1) party_expected = PoliticalParty.find_party('50plus') self.assertEqual(members[0].party, party_expected)
def test_create_parliament_member_from_wikidata_martin(self): person_wikidata_id = 'Q2801440' # Martin van Rooijen parliament = Parliament.get_or_create_tweede_kamer() members = openkamer.parliament.create_parliament_member_from_wikidata_id( parliament, person_wikidata_id) self.assertEqual(len(members), 1) party_expected = PoliticalParty.find_party('50plus') self.assertEqual(members[0].party, party_expected)
def test_create_paul(self): person_wikidata_id = 'Q18169519' # Paul Smeulders Person.objects.create(forename='Paul', surname='Smeulders', wikidata_id=person_wikidata_id) parliament = Parliament.get_or_create_tweede_kamer() members = openkamer.parliament.create_parliament_member_from_wikidata_id( parliament, person_wikidata_id) self.assertEqual(len(members), 1) member = members[0] party_expected = PoliticalParty.find_party('GroenLinks') self.assertEqual(member.party, party_expected) self.assertEqual(member.person.initials, '') member.person.update_info() self.assertEqual(member.person.initials, 'P.H.M.')
def test_create_paul(self): person_wikidata_id = 'Q18169519' # Paul Smeulders Person.objects.create( forename='Paul', surname='Smeulders', wikidata_id=person_wikidata_id ) parliament = Parliament.get_or_create_tweede_kamer() members = openkamer.parliament.create_parliament_member_from_wikidata_id(parliament, person_wikidata_id) self.assertEqual(len(members), 1) member = members[0] party_expected = PoliticalParty.find_party('GroenLinks') self.assertEqual(member.party, party_expected) self.assertEqual(member.person.initials, '') member.person.update_info() self.assertEqual(member.person.initials, 'P.H.M.')
def create_votes_party(self, voting, stemmingen): logger.info('BEGIN') for stemming in stemmingen: fractie_name = stemming.actor_fractie if stemming.actor_fractie else stemming.actor_naam party = PoliticalParty.find_party(fractie_name) if not party and self.do_create_missing_party: party = self.create_missing_party(stemming) if not stemming.soort: logger.warning('vote has no decision, vote.details: ' + str(stemming.soort)) VoteParty.objects.create( voting=voting, party=party, party_name=fractie_name, number_of_seats=stemming.fractie_size, decision=self.get_decision(stemming.soort), details='', is_mistake=stemming.vergissing if stemming.vergissing is not None else False ) logger.info('END')
def create_votes_party(self, voting, stemmingen): logger.info('BEGIN') for stemming in stemmingen: fractie_name = stemming.actor_fractie party = PoliticalParty.find_party(fractie_name) if not party and self.do_create_missing_party: party = self.create_missing_party(stemming) if not stemming.soort: logger.warning('vote has no decision, vote.details: ' + str(stemming.soort)) VoteParty.objects.create( voting=voting, party=party, party_name=fractie_name, number_of_seats=stemming.fractie_size, decision=self.get_decision(stemming.soort), details='', is_mistake=stemming.vergissing if stemming.vergissing is not None else False ) logger.info('END')
def test_find_party(self): name = 'Socialistische Partij' name_short = 'SP' party_expected = PoliticalParty.objects.create(name=name, name_short=name_short) party = PoliticalParty.find_party(name) self.assertEqual(party, party_expected) party = PoliticalParty.find_party(name_short) self.assertEqual(party, party_expected) party = PoliticalParty.find_party('sp') self.assertEqual(party, party_expected) party = PoliticalParty.find_party('SocialIstische parTij') self.assertEqual(party, party_expected) name = 'Group K/Ö' name_short = 'GrKO' party_expected = PoliticalParty.objects.create(name=name, name_short=name_short) party = PoliticalParty.find_party('GrKÖ') self.assertEqual(party, party_expected) party = PoliticalParty.find_party('GrKO') self.assertEqual(party, party_expected)
def set_derived(self): self.party = PoliticalParty.find_party(self.party_name) self.save()
def test_find_party_dash(self): party_expected = PoliticalParty.objects.create(name='Vrijzinnig Democratische Bond', name_short='VDB') party = PoliticalParty.find_party('Vrijzinnig Democratische Bond') self.assertEqual(party, party_expected) party = PoliticalParty.find_party('Vrijzinnig-Democratische Bond') self.assertEqual(party, party_expected)