├── .gitignore ├── LICENSE ├── LISCENCE.md ├── README.md ├── pymvrd ├── __init__.py ├── app.py └── errors.py ├── requirements.txt ├── setup.cfg └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # IPython Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | venv/ 83 | ENV/ 84 | 85 | # Spyder project settings 86 | .spyderproject 87 | 88 | # Rope project settings 89 | .ropeproject 90 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Obi Uchenna David 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LISCENCE.md: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Obi Uchenna David 4 | 5 | > Permission is hereby granted, free of charge, to any person obtaining a copy 6 | > of this software and associated documentation files (the "Software"), to deal 7 | > in the Software without restriction, including without limitation the rights 8 | > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | > copies of the Software, and to permit persons to whom the Software is 10 | > furnished to do so, subject to the following conditions: 11 | > 12 | > The above copyright notice and this permission notice shall be included in 13 | > all copies or substantial portions of the Software. 14 | > 15 | > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | > THE SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pymvrd ![https://pypi.python.org/pypi/pymvrd/0.6](https://badge.fury.io/py/pymvrd.svg) [![Say Thanks!](https://img.shields.io/badge/Say%20Thanks-!-1EAEDB.svg)](https://saythanks.io/to/othreecodes) 2 | ## Mvrd library - Grab all the Nigerian Vehicles Data!!! 3 | > Mvrd Library for Python 4 | 5 | ## Installation 6 | Requires 7 | - Python > 2.7 8 | 9 | ```shell 10 | pip install pymvrd #install pymvrd 11 | 12 | ``` 13 | 14 | ## Usage 15 | 16 | ```python 17 | 18 | from pymvrd.app import Mvrd 19 | 20 | if __name__ == '__main__': 21 | plate_num = Mvrd('') 22 | details = plate_num.get_data() 23 | # get_data() returns a dict 24 | print(details) 25 | 26 | # get indiviual Details 27 | print('Raw data ' + str(data)) 28 | print("Number :" + data.number()) 29 | print("Owner :" + data.owner_name()) 30 | print("Issue date :" + str(data.issue_date())) 31 | print("Vehicle Status :" + data.vehicle_status()) 32 | print("Chasis Number :" + data.chasis_number()) 33 | print("color :" + data.color()) 34 | print("Expiry :" + str(data.expiry_date())) 35 | print("Chasis Number :" + data.chasis_number()) 36 | 37 | # Raises InvalidPlateError If the plate number does not exist 38 | 39 | ``` 40 | 41 | ```python 42 | #sample output 43 | {'Isssue Date': '2011-11-24T13:26:31.630', 'Chasis Number': 'XXXXXXXXXXXX', 'Color': 'Ash', 'Plate Number': 'XXXXXXX', 'Model': 'Toyota Rav4', 'Expiry Date': '2012-11-23T13:26:31.630', 'Owner Name': 'Mr. . XXXXXXXX', 'Vehicle Status': 'Default'} 44 | 45 | Raw data {'Plate Number': 'XXXXXX', 'Model': 'Toyota Camry', 'Expiry Date': '2012-11-16T14:36:09.183', 'Color': 'Ash', 'Isssue Date': '2011-11-17T14:36:09.183', 'Chasis Number': 'XXXXXXXXX', 'Vehicle Status': 'Default', 'Owner Name': 'Mr. XXX XXXX .'} 46 | Number :XXXXX 47 | Owner :Mr. XXX XXX XX . 48 | Issue date :2011-11-17 14:36:09 49 | Vehicle Status :Default 50 | Chasis Number :XXXXXXXXXXXXXXX 51 | color :Ash 52 | Expiry :2012-11-16 14:36:09 53 | Chasis Number : XXXXXXXXXXX 54 | 55 | 56 | ``` 57 | 58 | Inspiration https://github.com/unicodeveloper/mvrd by @unicodeveloper 59 | 60 | ## Liscence 61 | MIT 62 | -------------------------------------------------------------------------------- /pymvrd/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/othreecodes/pymvrd/f92be4b4527a6624081355e1bd388c1744afe0ff/pymvrd/__init__.py -------------------------------------------------------------------------------- /pymvrd/app.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | ''' 4 | pyMVRD 5 | Nigerian Motor Vehicle Registration Lookup 6 | __author__ = 'othreecodes' 7 | ___ _ _ _ 8 | / _ \| |_| |__ _ __ ___ ___ ___ ___ __| | ___ ___ 9 | | | | | __| '_ \| '__/ _ \/ _ \/ __/ _ \ / _` |/ _ \/ __| 10 | | |_| | |_| | | | | | __/ __/ (_| (_) | (_| | __/\__ \ 11 | \___/ \__|_| |_|_| \___|\___|\___\___/ \__,_|\___||___/ 12 | 13 | ''' 14 | import requests 15 | from bs4 import BeautifulSoup 16 | from datetime import datetime 17 | import re 18 | from pymvrd.errors import * 19 | 20 | BASE_URL = 'http://www.lsmvaapvs.org' 21 | 22 | 23 | def parse_response(response): 24 | soup = BeautifulSoup(response.text, "html.parser") 25 | try: 26 | data = soup.find_all('td') 27 | except: 28 | raise InvalidPlateError 29 | 30 | # Cleaning the HTML tags from the string 31 | for i in range(0, len(data)): 32 | data[i] = clean_html_tags(str(data[i])) 33 | 34 | # Turning the list into a dict 35 | data_dict = dict(zip(*[iter(data)] * 2)) 36 | return data_dict 37 | 38 | 39 | def clean_html_tags(raw_html): 40 | # Clean the HTML tags from response 41 | clean = re.compile('<.*?>') 42 | clean_text = re.sub(clean, '', raw_html) 43 | return clean_text 44 | 45 | 46 | class Plate: 47 | def __init__(self, raw_data): 48 | self.raw_data = raw_data 49 | 50 | def __str__(self): 51 | return str(self.raw_data) 52 | 53 | def __unicode__(self): 54 | return str(self.raw_data) 55 | 56 | def number(self): 57 | return self.raw_data['Plate Number'] 58 | 59 | def issue_date(self): 60 | date = self.raw_data['Isssue Date'][0:-4] 61 | date_object = datetime.strptime(date, '%Y-%m-%dT%H:%M:%S') 62 | return date_object 63 | 64 | def vehicle_status(self): 65 | return self.raw_data['Vehicle Status'] 66 | 67 | def chasis_number(self): 68 | return self.raw_data['Chasis Number'] 69 | 70 | def expiry_date(self): 71 | date = self.raw_data['Expiry Date'][0:-4] 72 | date_object = datetime.strptime(date, '%Y-%m-%dT%H:%M:%S') 73 | return date_object 74 | 75 | def owner_name(self): 76 | return self.raw_data['Owner Name'] 77 | 78 | def model(self): 79 | return self.raw_data['Model'] 80 | 81 | def color(self): 82 | return self.raw_data['Color'] 83 | 84 | 85 | class Mvrd: 86 | '''MVRD Class''' 87 | 88 | def __init__(self, plate_number): 89 | self.plate_number = plate_number 90 | 91 | '''Getting the raw html from www.lsmvaapvs.org''' 92 | 93 | def get_data(self): 94 | response = requests.get(BASE_URL + '/search.php', {'vpn': self.plate_number}) 95 | data = parse_response(response=response) 96 | if data == {}: 97 | raise InvalidPlateError("The Plate number does not exist") 98 | 99 | pretty_data = Plate(data) 100 | return pretty_data 101 | -------------------------------------------------------------------------------- /pymvrd/errors.py: -------------------------------------------------------------------------------- 1 | class Mvrd(Exception): 2 | ''' 3 | MVRD Exception 4 | ''' 5 | pass 6 | 7 | class InvalidPlateError(Exception): 8 | ''' 9 | The Plate number Entered was Invalid 10 | ''' 11 | 12 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | bs4 2 | requests 3 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | description-file = README.md 3 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup 2 | setup( 3 | name = 'pymvrd', 4 | packages = ['pymvrd'], 5 | version = '0.1', 6 | description = 'Motor Vehicle Registration Information Search Portal Library', 7 | author = 'Obi Uchenna David', 8 | author_email = 'daviduchenna@outlook.com', 9 | url = 'https://github.com/othreecodes/pymvrd', 10 | download_url = 'https://github.com/othreecodes/pymvrd/tarball/0.1', 11 | keywords = ['vehicle','plate number','registration'], 12 | classifiers = [], 13 | install_requires=[ 14 | 'requests', 15 | 'bs4', 16 | ], 17 | ) 18 | --------------------------------------------------------------------------------