-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from j4asper/v1
Merge v1.0.0 update
- Loading branch information
Showing
19 changed files
with
334 additions
and
692 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,4 +129,6 @@ dmypy.json | |
.pyre/ | ||
|
||
# VS Code config folder | ||
.vscode | ||
.vscode | ||
|
||
.idea |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
from .dmr_model import DMR | ||
from .insurance_model import Insurance | ||
from .models.insurance import Insurance | ||
from .models.vehicle import Vehicle | ||
from .models.propulsion_type import PropulsionType | ||
from .models.vehicle_type import VehicleType | ||
from .models.body_type import BodyType | ||
from .models.use_type import UseType | ||
from dmr.dmr import DMR |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from __future__ import annotations | ||
from typing import Optional | ||
from dmr.models.vehicle import Vehicle | ||
from re import search, RegexFlag | ||
from dmr.utils import ( | ||
scrape_async, | ||
scrape, | ||
errors, | ||
) | ||
|
||
|
||
class DMR: | ||
|
||
@classmethod | ||
def validate_license_plate(cls, license_plate: str) -> bool: | ||
"""Checks if the given string can be a license plate, this check is also run prior to the webscraping. | ||
Args: | ||
license_plate (str): The license plate to check | ||
Returns: | ||
bool: Returns True if the given license plate could be a license plate, or False if not. | ||
""" | ||
|
||
match = search(r"^[A-Z0-9]{2,7}$", license_plate.upper()) | ||
if match: | ||
return True | ||
else: | ||
return False | ||
|
||
|
||
@classmethod | ||
def get_by_plate(cls, license_plate: str) -> Optional[Vehicle]: | ||
"""Get data from DMR by license plate. | ||
Args: | ||
license_plate (str): The license plate to look up. Not required if license plate was passed into the DMR object. | ||
Raises: | ||
InvalidLicensePlate: Invalid license plate was given | ||
Returns: | ||
DMR: DMR object is returned, check https://github.com/j4asper/dmr.py/wiki for more information. | ||
""" | ||
|
||
if not cls.validate_license_plate(license_plate): | ||
raise errors.InvalidLicensePlate("Invalid license plate. license plate length should be between 2 and 7 letters and/or digits.") | ||
|
||
data = scrape(license_plate=license_plate) | ||
if data: | ||
return Vehicle(**data) | ||
else: | ||
return None | ||
|
||
|
||
@classmethod | ||
async def get_by_plate_async(cls, license_plate: str): | ||
"""Get data from DMR asynchronously by license plate. | ||
Args: | ||
license_plate (str): The license plate to look up. | ||
Raises: | ||
InvalidLicensePlate: Invalid license plate was given | ||
Returns: | ||
DMR: DMR object is returned, check https://github.com/j4asper/dmr.py/wiki for more information. | ||
""" | ||
|
||
if not cls.validate_license_plate(license_plate): | ||
raise errors.InvalidLicensePlate( | ||
"Invalid license plate. license plate length should be between 2 and 7 letters and/or digits.") | ||
|
||
data = await scrape_async(license_plate=license_plate) | ||
if data: | ||
return Vehicle(**data) | ||
else: | ||
return None |
Oops, something went wrong.