Skip to content

Commit acb04e0

Browse files
committed
v0.0.2
Signed-off-by: Finbarrs Oketunji <f@finbarrs.eu>
1 parent 4382f26 commit acb04e0

7 files changed

+67
-22
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Changelog
22

3+
## 0.0.2 - 2023-02-18
4+
* Errors and Exception Handling
5+
36
## 0.0.1 - 2023-02-17
47
* Initial release

LONG_DESCRIPTION.rst

+17-7
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,40 @@ Usage Example
3838
.. code-block:: python
3939
4040
from motapi.motdata import *
41-
from dotenv import load_dotenv
42-
import os
4341
4442
api_key = "<your-api-key>" # your api key
4543
registration = "ML58FOU" # example of a vehicle registration
4644
page = 1 # pagination
4745
date = "20230201" # date must be five weeks from the current date
48-
vehicle_id = "<enter your vehicle id here>" # unique vehicle ID for vehicles that have had an MOT test
46+
vehicle_id = "<enter your vehicle id here>" # unique vehicle id for vehicles that have had an MOT test
4947
5048
reg = Registration(api_key)
5149
reg_data = reg.get_data(registration)
52-
print(reg_data)
50+
if reg_data is not None:
51+
print(reg_data)
52+
else:
53+
print("Failed to retrieve data!")
5354
5455
p = Page(api_key)
5556
page_data = p.get_data(page)
56-
print(page_data)
57+
if page_data is not None:
58+
print(page_data)
59+
else:
60+
print("Failed to retrieve data!")
5761
5862
d = Date(api_key)
5963
date_data = d.get_data(date, page)
60-
print(date_data)
64+
if date_data is not None:
65+
print(date_data)
66+
else:
67+
print("Failed to retrieve data!")
6168
6269
v = VehicleID(api_key)
6370
vehicle_data = v.get_data(vehicle_id)
64-
print(vehicle_data)
71+
if vehicle_data is not None:
72+
print(vehicle_data)
73+
else:
74+
print("Failed to retrieve data!")
6575
6676
6777
Request MOT History API Key

README.md

+19-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# MOT History API Python SDK
22

3+
[![PyPI version](https://badge.fury.io/py/mot-history-api-py-sdk.svg)](https://badge.fury.io/py/mot-history-api-py-sdk)
4+
35
The SDK provides convenient access to the [MOT History API](https://dvsa.github.io/mot-history-api-documentation/) for applications written in the Python programming language.
46

57
## Requirements
@@ -30,30 +32,40 @@ python setup.py install --user
3032

3133
```python
3234
from motapi.motdata import *
33-
from dotenv import load_dotenv
34-
import os
3535

3636
api_key = "<your-api-key>" # your api key
3737
registration = "ML58FOU" # example of a vehicle registration
3838
page = 1 # pagination
3939
date = "20230201" # date must be five weeks from the current date
40-
vehicle_id = "<enter your vehicle id here>" # unique vehicle ID for vehicles that have had an MOT test
40+
vehicle_id = "<enter your vehicle id here>" # unique vehicle id for vehicles that have had an MOT test
4141

4242
reg = Registration(api_key)
4343
reg_data = reg.get_data(registration)
44-
print(reg_data)
44+
if reg_data is not None:
45+
print(reg_data)
46+
else:
47+
print("Failed to retrieve data!")
4548

4649
p = Page(api_key)
4750
page_data = p.get_data(page)
48-
print(page_data)
51+
if page_data is not None:
52+
print(page_data)
53+
else:
54+
print("Failed to retrieve data!")
4955

5056
d = Date(api_key)
5157
date_data = d.get_data(date, page)
52-
print(date_data)
58+
if date_data is not None:
59+
print(date_data)
60+
else:
61+
print("Failed to retrieve data!")
5362

5463
v = VehicleID(api_key)
5564
vehicle_data = v.get_data(vehicle_id)
56-
print(vehicle_data)
65+
if vehicle_data is not None:
66+
print(vehicle_data)
67+
else:
68+
print("Failed to retrieve data!")
5769
```
5870

5971
## Setting up a MOT History API

motapi/motdata.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,17 @@ def get_headers(self):
1313
def make_request(self, url, params=None):
1414
headers = self.get_headers()
1515
response = requests.get(url, headers=headers, params=params)
16-
response.raise_for_status()
17-
return response.json()
16+
try:
17+
response.raise_for_status()
18+
except requests.exceptions.HTTPError as error:
19+
print(f"HTTP error occurred: {error}")
20+
return None
21+
try:
22+
data = response.json()
23+
except ValueError:
24+
print(f"Failed to parse response as JSON: {response.text}")
25+
return None
26+
return data
1827

1928

2029
class Registration(CheckMOTAPI):

requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
python-dotenv
21
requests

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from distutils.core import Extension
66

77
NAME = "mot-history-api-py-sdk"
8-
VERSION = "0.0.1"
8+
VERSION = "0.0.2"
99
REQUIRES = ["requests"]
1010

1111
# read the contents of your README file

test.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,28 @@
88

99
reg = Registration(api_key)
1010
reg_data = reg.get_data(registration)
11-
print(reg_data)
11+
if reg_data is not None:
12+
print(reg_data)
13+
else:
14+
print("Failed to retrieve data!")
1215

1316
p = Page(api_key)
1417
page_data = p.get_data(page)
15-
print(page_data)
18+
if page_data is not None:
19+
print(page_data)
20+
else:
21+
print("Failed to retrieve data!")
1622

1723
d = Date(api_key)
1824
date_data = d.get_data(date, page)
19-
print(date_data)
25+
if date_data is not None:
26+
print(date_data)
27+
else:
28+
print("Failed to retrieve data!")
2029

2130
v = VehicleID(api_key)
2231
vehicle_data = v.get_data(vehicle_id)
23-
print(vehicle_data)
32+
if vehicle_data is not None:
33+
print(vehicle_data)
34+
else:
35+
print("Failed to retrieve data!")

0 commit comments

Comments
 (0)