Skip to content

Commit

Permalink
Updated Folder Structure
Browse files Browse the repository at this point in the history
Created Plate class to enable developer get data easier
Cleaned Code
  • Loading branch information
othreecodes committed Dec 27, 2016
1 parent a245459 commit 10b32e2
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 13 deletions.
Empty file added pymvrd/__init__.py
Empty file.
76 changes: 63 additions & 13 deletions pymvrd/app.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,94 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

'''
pyMVRD
Nigerian Motor Vehicle Registration Lookup
__author__ = 'othreecodes'

'''
import requests
from bs4 import BeautifulSoup
BASE_URL = 'http://www.lsmvaapvs.org'
from datetime import datetime
import re
from .errors.errors import *
from pymvrd.errors import *

BASE_URL = 'http://www.lsmvaapvs.org'


def parse_response(response):
soup = BeautifulSoup(response.text,"html.parser")
soup = BeautifulSoup(response.text, "html.parser")
try:
data = soup.find_all('td')
except:
raise InvalidPlateError

'''Cleaning the HTML tags from the string'''
for i in range(0,len(data)):
# Cleaning the HTML tags from the string
for i in range(0, len(data)):
data[i] = clean_html_tags(str(data[i]))

'''Turning the list into a dict'''
# Turning the list into a dict
data_dict = dict(zip(*[iter(data)] * 2))
return data_dict


'''Clean the HTML tags from response'''
def clean_html_tags(raw_html):
# Clean the HTML tags from response
clean = re.compile('<.*?>')
clean_text = re.sub(clean, '', raw_html)
return clean_text

'''MVRD class'''

class Plate:
def __init__(self, raw_data):
self.raw_data = raw_data

def __str__(self):
return str(self.raw_data)

def __unicode__(self):
return str(self.raw_data)

def number(self):
return self.raw_data['Plate Number']

def issue_date(self):
date = self.raw_data['Isssue Date'][0:-4]
date_object = datetime.strptime(date, '%Y-%m-%dT%H:%M:%S')
return date_object

def vehicle_status(self):
return self.raw_data['Vehicle Status']

def chasis_number(self):
return self.raw_data['Chasis Number']

def expiry_date(self):
date = self.raw_data['Expiry Date'][0:-4]
date_object = datetime.strptime(date, '%Y-%m-%dT%H:%M:%S')
return date_object

def owner_name(self):
return self.raw_data['Owner Name']

def model(self):
return self.raw_data['Model']

def color(self):
return self.raw_data['Color']


class Mvrd:
def __init__(self,plate_number):
'''MVRD Class'''

def __init__(self, plate_number):
self.plate_number = plate_number

'''Getting the raw html from www.lsmvaapvs.org'''

def get_data(self):
response = requests.get(BASE_URL+'/search.php',{'vpn':self.plate_number})
response = requests.get(BASE_URL + '/search.php', {'vpn': self.plate_number})
data = parse_response(response=response)
return data
if data == {}:
raise InvalidPlateError("The Plate number does not exist")

pretty_data = Plate(data)
return pretty_data
File renamed without changes.
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bs4
requests
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@
download_url = 'https://github.com/othreecodes/pymvrd/tarball/0.1',
keywords = ['vehicle','plate number','registration'],
classifiers = [],
install_requires=[
'requests',
'bs4',
],
)

0 comments on commit 10b32e2

Please sign in to comment.