def test_get_kamervragen_old(self): start_datetime = datetime.datetime(year=2008, month=7, day=4) end_datetime = datetime.datetime(year=2008, month=7, day=5) kv_filter = ParlementairDocument.create_filter() kv_filter.filter_date_range(start_datetime, end_datetime) kamervragen = api.get_kamervragen(kv_filter) self.assertEqual(len(kamervragen), 3)
def test_get_dossiers(self): pd_filter = ParlementairDocument.create_filter() # start_datetime = datetime.datetime(year=2016, month=1, day=1) # end_datetime = datetime.datetime(year=2017, month=6, day=1) # pd_filter.filter_date_range(start_datetime, end_datetime) pd_filter.filter_soort('Voorstel van wet', is_or=True) pd_filter.filter_soort('Voorstel van wet (initiatiefvoorstel)', is_or=True) pds = api.get_parlementaire_documenten(pd_filter) dossier_nrs = [] pds_no_dossier_nr = [] for pd in pds: print(pd.dossier_vetnummer) if pd.dossier_vetnummer: dossier_nrs.append(pd.dossier_vetnummer) else: pds_no_dossier_nr.append(pd) for pd in pds_no_dossier_nr: print(pd.nummer) print(pd.onderwerp) try: dossier_nr = int( pd.onderwerp.split('Voorstel van wet')[0].strip()) dossier_nrs.append(dossier_nr) except TypeError: continue dossier_nrs = OrderedSet(sorted(dossier_nrs)) print(dossier_nrs) for dossier_nr in dossier_nrs: print(dossier_nr) print(len(dossier_nrs))
def test_get_kamervragen_new(self): start_datetime = datetime.datetime(year=2015, month=1, day=1) end_datetime = datetime.datetime(year=2015, month=1, day=7) kv_filter = ParlementairDocument.create_filter() kv_filter.filter_date_range(start_datetime, end_datetime) kamervragen = api.get_kamervragen(kv_filter) self.assertEqual(len(kamervragen), 11)
def main(): print('BEGIN') year = 2016 start_datetime = datetime.datetime(year=year, month=1, day=1) end_datetime = datetime.datetime(year=year + 1, month=1, day=1) pd_filter = ParlementairDocument.create_filter() pd_filter.filter_date_range(start_datetime, end_datetime) verslagen = api.get_verslagen_van_algemeen_overleg(pd_filter) with open('verslagen_algemeen_overleg_' + str(year) + '.csv', 'w') as fileout: header = ','.join([ 'datum gepubliceerd', 'dossier nr', 'dossier toevoeging', 'kamerstuk ondernummer', 'url' ]) fileout.write(header + '\n') for verslag in verslagen: if not verslag.kamerstuk or not verslag.dossier: print('WARNING: no kamerstuk or dossier number found for ' + str(verslag.datum)) continue toevoeging = '' if verslag.dossier.toevoeging: toevoeging = verslag.dossier.toevoeging row = ','.join([ verslag.datum.strftime('%Y-%m-%d'), str(verslag.dossier.vetnummer), toevoeging, str(verslag.kamerstuk.ondernummer), verslag.document_url ]) fileout.write(row + '\n') print('END')
def test_get_antwoorden_2010(self): start_datetime = datetime.datetime(year=2010, month=1, day=1) end_datetime = datetime.datetime(year=2010, month=1, day=10) kv_filter = ParlementairDocument.create_filter() kv_filter.filter_date_range(start_datetime, end_datetime) antwoorden = api.get_antwoorden(kv_filter) self.assertEqual(len(antwoorden), 2)
def main(): print('BEGIN') # years = [2010, 2011, 2012, 2013, 2014, 2015, 2016] years = [2017, 2018] month = 1 out_dir = os.path.join(parentdir, '../ok-tk-data/kamervragen/') api = tkapi.Api(user=USER, password=PASSWORD, api_root=API_ROOT_URL, verbose=True) for year in years: start_datetime = datetime.datetime(year=year, month=month, day=1) end_datetime = datetime.datetime(year=year + 1, month=month, day=1) kv_filter = ParlementairDocument.create_filter() kv_filter.filter_date_range(start_datetime, end_datetime) kamervragen = api.get_kamervragen(kv_filter) with open(os.path.join(out_dir, 'kamervragen_' + str(year) + '.csv'), 'w') as fileout: fileout.write('datum' + ',' + 'vraag nummer' + ',' + 'url' + '\n') for vraag in kamervragen: fileout.write( vraag.datum.strftime('%Y-%m-%d') + ',' + vraag.nummer + ',' + vraag.document_url + '\n') print('END')
def test_filter_titel(self): titel = 'Wijziging van de Warmtewet (wijzigingen naar aanleiding van de evaluatie van de Warmtewet)' pd_filter = ParlementairDocument.create_filter() pd_filter.filter_titel(titel) pds = api.get_parlementaire_documenten(pd_filter) self.assertTrue(len(pds) >= 7) for pd in pds: self.assertEqual(pd.titel, titel)
def parlementaire_documenten(self): parlementair_documenten = [] for kamerstuk in self.json['Kamerstuk']: if kamerstuk == '': continue pds = kamerstuk['ParlementairDocument'] pd = ParlementairDocument(pds) parlementair_documenten.append(pd) return parlementair_documenten
def test_all_soorten(self): pd_filter = ParlementairDocument.create_filter() start_datetime = datetime.datetime(year=2010, month=1, day=1) end_datetime = datetime.datetime(year=2010, month=2, day=1) pd_filter.filter_date_range(start_datetime, end_datetime) pds = api.get_parlementaire_documenten(pd_filter) soorten = [] for pd in pds: soorten.append(pd.soort) soorten = OrderedSet(sorted(soorten)) for soort in soorten: print(soort)
def test_get_voorstel_van_wet(self): pd_filter = ParlementairDocument.create_filter() pd_filter.filter_date_range(TestParlementairDocument.start_datetime, TestParlementairDocument.end_datetime) pd_filter.filter_soort('Voorstel van wet', is_or=True) pd_filter.filter_soort('Voorstel van wet (initiatiefvoorstel)', is_or=True) # print(pd_filter.filter_str) pds = api.get_parlementaire_documenten(pd_filter) for pd in pds: print(pd.titel) print(pd.activiteiten)
def test_get_wetsvoorstel_document_without_kamerstuk_and_dossier(self): pd_filter = ParlementairDocument.create_filter() pd_filter.filter_soort('Voorstel van wet', is_or=True) pd_filter.filter_soort('Voorstel van wet (initiatiefvoorstel)', is_or=True) pds = api.get_parlementaire_documenten(pd_filter) pds_no_dossier_nr = [] for pd in pds: if not pd.dossier_vetnummer: pds_no_dossier_nr.append(pd) print('wetsvoorstellen without dossier: ' + str(len(pds_no_dossier_nr))) self.assertEqual(len(pds_no_dossier_nr), 0)
def test_filter_empty_agendapunt(self): pd_filter = ParlementairDocument.create_filter() start_datetime = datetime.datetime(year=2005, month=1, day=1) end_datetime = datetime.datetime.now() pd_filter.filter_date_range(start_datetime, end_datetime) pd_filter.filter_empty_agendapunt() pds = api.get_parlementaire_documenten(pd_filter) for pd in pds: print('\n============') print(pd.titel) for zaak in pd.zaken: print(zaak) print(len(pds))
def test_get_kamervragen_2013(self): start_datetime = datetime.datetime(year=2013, month=1, day=1) end_datetime = datetime.datetime(year=2013, month=2, day=1) pd_filter = ParlementairDocument.create_filter() pd_filter.filter_date_range(start_datetime, end_datetime) pd_filter.filter_soort('Schriftelijke vragen') schriftelijke_vragen = api.get_parlementaire_documenten(pd_filter) kamervragen_no_zaak = [] for kamervraag in schriftelijke_vragen: if not kamervraag.zaken: kamervragen_no_zaak.append(kamervraag) print('kamervragen without zaak: ' + str(len(kamervragen_no_zaak))) self.assertEqual(0, len(kamervragen_no_zaak))
def test_filter_empty_zaak(self): pd_filter = ParlementairDocument.create_filter() start_datetime = datetime.datetime(year=2017, month=1, day=1) end_datetime = datetime.datetime(year=2017, month=2, day=1) pd_filter.filter_date_range(start_datetime, end_datetime) pd_filter.filter_soort('Voorstel van wet') pd_filter.filter_empty_zaak() pds = api.get_parlementaire_documenten(pd_filter) for pd in pds: print('\n============') print(pd.titel) for zaak in pd.zaken: print(zaak) print(len(pds))
def main(): print('BEGIN') year = 2017 api = tkapi.Api(user=USER, password=PASSWORD, verbose=True) start_datetime = datetime.datetime(year=year, month=1, day=1) end_datetime = datetime.datetime(year=year + 1, month=1, day=1) kv_filter = ParlementairDocument.create_filter() kv_filter.filter_date_range(start_datetime, end_datetime) antwoorden = api.get_antwoorden(kv_filter) with open('antwoorden_' + str(year) + '.csv', 'w') as fileout: fileout.write('datum' + ',' + 'antwoord nummer' + ',' + 'url' + '\n') for antwoord in antwoorden: fileout.write( antwoord.datum.strftime('%Y-%m-%d') + ',' + antwoord.nummer + ',' + antwoord.document_url + '\n') print('END')
def main(): print('BEGIN') out_dir = os.path.join(parentdir, '../ok-tk-data/wetsvoorstellen/') pd_filter = ParlementairDocument.create_filter() # start_datetime = datetime.datetime(year=2016, month=1, day=1) # end_datetime = datetime.datetime(year=2017, month=6, day=1) # pd_filter.filter_date_range(start_datetime, end_datetime) pd_filter.filter_soort('Voorstel van wet', is_or=True) pd_filter.filter_soort('Voorstel van wet (initiatiefvoorstel)', is_or=True) pds = api.get_parlementaire_documenten(pd_filter) dossier_nrs = [] pds_no_dossier_nr = [] for pd in pds: if pd.dossier_vetnummer: dossier_nrs.append(pd.dossier_vetnummer) else: pds_no_dossier_nr.append(pd) for pd in pds_no_dossier_nr: try: dossier_nr_str = pd.onderwerp.lower().split( 'voorstel van wet')[0].strip() if dossier_nr_str == '': print('WARNING: empty dossier nr in: ' + pd.onderwerp) continue dossier_nr_str = dossier_nr_str.split('(')[0].strip( ) # for Rijkswetten '(R2096)' remove the rijkswet ID dossier_nr = int(dossier_nr_str) dossier_nrs.append(dossier_nr) except (TypeError, ValueError): print('WARNING: could not extract dossier nr from: ' + pd.onderwerp) continue dossier_nrs = OrderedSet(sorted(dossier_nrs)) print(dossier_nrs) for dossier_nr in dossier_nrs: print(dossier_nr) print(len(dossier_nrs)) with open(os.path.join(out_dir, 'wetsvoorstellen_dossier_ids' + '.txt'), 'w') as fileout: for dossier_nr in dossier_nrs: fileout.write(str(dossier_nr) + '\n') print('END')
def test_filter_mixin(self): pd_filter = ParlementairDocument.create_filter() pd_filter.filter_soort('test soort') pd_filter.filter_empty_zaak() self.assertEqual(len(pd_filter.filters), 2)
def test_get_kamervragen_2013(self): start_datetime = datetime.datetime(year=2013, month=1, day=31) end_datetime = datetime.datetime(year=2013, month=2, day=1) kv_filter = ParlementairDocument.create_filter() kv_filter.filter_date_range(start_datetime, end_datetime) kamervragen = api.get_kamervragen(kv_filter)