Last active
June 1, 2023 22:27
-
-
Save Lytrix/300b8832086c7b999fb975c1a63c13e7 to your computer and use it in GitHub Desktop.
Retrieve vehicle details from Dutch vehicle database https://ovi.rdw.nl from RDW using a license plate.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import requests\n", | |
"import json" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 15, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def get_vehicle_details(uri, license_plate, field='all'):\n", | |
" \"\"\"\n", | |
" Get vehicle data based on a license plate from RDW: https://ovi.rdw.nl\n", | |
" \n", | |
" Args:\n", | |
" license plate: Add numbers/characters without stripes or spaces, for example: 63BKP7\n", | |
" field: if kept empty, all values are return, if a field is defined, only that field will return, for example: 'toegestane_maximum_massa_voertuig' \n", | |
" Returns:\n", | |
" dictonary or 1 value, for example '19500'\n", | |
" \"\"\"\n", | |
" url = uri + '?$where=kenteken='\n", | |
" request_url = '{}\\'{}\\''.format(url, license_plate) #added \\' to solve sql error in request\n", | |
" print('requesting: ',request_url)\n", | |
" request = requests.get(request_url) \n", | |
" response = json.loads(request.text)\n", | |
" if field == 'all':\n", | |
" element = response[0]\n", | |
" else:\n", | |
" element = response[0][field]\n", | |
" try:\n", | |
" element = int(element)\n", | |
" except ValueError:\n", | |
" print('Not a int, parsing as string.')\n", | |
" print(field, ': ',element)\n", | |
" return element" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 16, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"requesting: http://opendata.rdw.nl/api/id/m9d7-ebf2.json?$where=kenteken='63BKP7'\n", | |
"all : {'aantal_cilinders': '6', 'aantal_wielen': '4', 'aantal_zitplaatsen': '2', 'afstand_voorzijde_voertuig_tot_hart_koppeling': '450', 'api_gekentekende_voertuigen_assen': 'https://opendata.rdw.nl/resource/3huj-srit.json', 'api_gekentekende_voertuigen_brandstof': 'https://opendata.rdw.nl/resource/8ys7-d773.json', 'api_gekentekende_voertuigen_carrosserie': 'https://opendata.rdw.nl/resource/vezc-m2t6.json', 'api_gekentekende_voertuigen_carrosserie_specifiek': 'https://opendata.rdw.nl/resource/jhie-znh9.json', 'api_gekentekende_voertuigen_voertuigklasse': 'https://opendata.rdw.nl/resource/kmfi-hrps.json', 'breedte': '255', 'cilinderinhoud': '12809', 'datum_eerste_afgifte_nederland': '15/03/2018', 'datum_eerste_toelating': '15/03/2018', 'datum_tenaamstelling': '15/03/2018', 'eerste_kleur': 'N.v.t.', 'europese_voertuigcategorie': 'N3', 'export_indicator': 'Nee', 'handelsbenaming': 'ACTROS', 'inrichting': 'opleggertrekker', 'kenteken': '63BKP7', 'lengte': '616', 'massa_ledig_voertuig': '8244', 'massa_rijklaar': '8344', 'maximum_massa_samenstelling': '50000', 'merk': 'MERCEDES-BENZ', 'openstaande_terugroepactie_indicator': 'Nee', 'oplegger_geremd': '41656', 'plaats_chassisnummer': 'op balk v. r.', 'retrofit_roetfilter': 'Nee', 'taxi_indicator': 'Nee', 'technische_max_massa_voertuig': '20500', 'toegestane_maximum_massa_voertuig': '19500', 'tweede_kleur': 'N.v.t.', 'type': '963-4-A', 'typegoedkeuringsnummer': 'e1*2007/46*0727*12', 'uitvoering': 'A060J1GABSBXX', 'variant': 'KSDM3CT21AXA230', 'vermogen_massarijklaar': '0.04', 'vervaldatum_apk': '15/03/2019', 'vervaldatum_tachograaf': '15/03/2020', 'voertuigsoort': 'Bedrijfsauto', 'volgnummer_wijziging_eu_typegoedkeuring': '0', 'wacht_op_keuren': 'Geen verstrekking in Open Data', 'wam_verzekerd': 'Ja', 'wielbasis': '370'}\n" | |
] | |
} | |
], | |
"source": [ | |
"all_vehicle_details = get_vehicle_details('http://opendata.rdw.nl/api/id/m9d7-ebf2.json','63BKP7')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 17, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"requesting: http://opendata.rdw.nl/api/id/m9d7-ebf2.json?$where=kenteken='63BKP7'\n", | |
"toegestane_maximum_massa_voertuig : 19500\n" | |
] | |
} | |
], | |
"source": [ | |
"toegestane_maximum_massa_voertuig = get_vehicle_details('http://opendata.rdw.nl/api/id/m9d7-ebf2.json','63BKP7','toegestane_maximum_massa_voertuig')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 29, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def get_vehicle_subinformation(url, license_plate, key_name_api, key_name):\n", | |
" \"\"\"\n", | |
" Args:\n", | |
" url: endpoint of the data, for example: 'http://opendata.rdw.nl/api/id/m9d7-ebf2.json'\n", | |
" license_plate: Add numbers/characters without stripes or spaces, for example: '63BKP7' \n", | |
" key_name_api: key name where the value contains the url of the api, for example 'api_gekentekende_voertuigen_assen'\n", | |
" key_name: name of the key you want to retrieve the value from, for example: 'wettelijk_toegestane_maximum_aslast'\n", | |
" Returns:\n", | |
" all object attributes\n", | |
" and the field you explicitly chosen as key_name:\n", | |
" wettelijk_toegestane_maximum_aslast : 11500\n", | |
" \"\"\"\n", | |
" uri = get_vehicle_details(url, license_plate, key_name_api)\n", | |
" get_vehicle_details(uri, license_plate)\n", | |
" get_vehicle_details(uri, license_plate, key_name)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 30, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"requesting: http://opendata.rdw.nl/api/id/m9d7-ebf2.json?$where=kenteken='63BKP7'\n", | |
"Not a int, parsing as string.\n", | |
"api_gekentekende_voertuigen_assen : https://opendata.rdw.nl/resource/3huj-srit.json\n", | |
"requesting: https://opendata.rdw.nl/resource/3huj-srit.json?$where=kenteken='63BKP7'\n", | |
"all : {'aangedreven_as': 'J', 'aantal_assen': '2', 'as_nummer': '2', 'hefas': 'N', 'kenteken': '63BKP7', 'plaatscode_as': 'A', 'technisch_toegestane_maximum_aslast': '13000', 'weggedrag_code': 'G', 'wettelijk_toegestane_maximum_aslast': '11500'}\n", | |
"requesting: https://opendata.rdw.nl/resource/3huj-srit.json?$where=kenteken='63BKP7'\n", | |
"wettelijk_toegestane_maximum_aslast : 11500\n" | |
] | |
} | |
], | |
"source": [ | |
"wettelijk_toegestane_maximum_aslast = get_vehicle_subinformation('http://opendata.rdw.nl/api/id/m9d7-ebf2.json','63BKP7','api_gekentekende_voertuigen_assen','wettelijk_toegestane_maximum_aslast')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.4" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment