-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvehicle_info_tool.py
More file actions
99 lines (85 loc) · 3.23 KB
/
vehicle_info_tool.py
File metadata and controls
99 lines (85 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env python3
import requests
import json
import sys
import argparse
from typing import Dict, Any, List, Optional, Union
def get_vehicle_info(mispar_rechev: int):
"""
Query the data.gov.il API for vehicle information using the vehicle number.
Args:
mispar_rechev: The vehicle number to search for
Returns:
The vehicle records or error message
"""
base_url = "https://data.gov.il/api/3/action/datastore_search"
params = {
'resource_id': '053cea08-09bc-40ec-8f7a-156f0677aff3',
'limit': 5,
'q': mispar_rechev
}
try:
response = requests.get(base_url, params=params)
if response.status_code == 200:
data = response.json()
# Check if the response contains records
if data.get('success') and 'result' in data:
records = data['result'].get('records', [])
if records:
return records
else:
return "No records found for this vehicle number"
else:
return "API response format error or no data available"
else:
return f"Error: {response.status_code}"
except Exception as e:
return f"Request error: {str(e)}"
def format_vehicle_info(records):
"""Format vehicle records into a more readable structure"""
if not isinstance(records, list):
return {"error": records}
formatted_results = []
for record in records:
formatted_record = {
"vehicle_number": record.get('mispar_rechev', 'N/A'),
"manufacturer": record.get('tozeret_nm', 'N/A'),
"type": record.get('kinuy_mishari', 'N/A'),
"badge": record.get('ramat_gimur', 'N/A'),
"chassis": record.get('misgeret', 'N/A'),
"model": record.get('degem_nm', 'N/A'),
"year": record.get('shnat_yitzur', 'N/A'),
"color": record.get('tzeva_rechev', 'N/A'),
"fuel_type": record.get('sug_delek_nm', 'N/A'),
"last_test_date": record.get('mivchan_acharon_dt', 'N/A'),
"license_valid_until": record.get('tokef_dt', 'N/A'),
"ownership": record.get('baalut', 'N/A'),
"all_details": record # Include all original fields
}
formatted_results.append(formatted_record)
return formatted_results
def main():
# Set up argument parser
parser = argparse.ArgumentParser(description="Look up vehicle information by license plate")
parser.add_argument("license_plate", help="Vehicle license plate number to look up")
args = parser.parse_args()
# Get vehicle info
records = get_vehicle_info(args.license_plate)
formatted_info = format_vehicle_info(records)
# Prepare the result
if isinstance(formatted_info, list) and formatted_info:
result = {
"success": True,
"count": len(formatted_info),
"vehicles": formatted_info
}
else:
result = {
"success": False,
"error": formatted_info.get("error", "Unknown error"),
"vehicles": []
}
# Output as JSON
print(json.dumps(result))
if __name__ == "__main__":
main()