vdmAPI/VDMAPI/VDM.py

35 lines
803 B
Python

from .HtmlParser import MyHTMLParser
import requests
class VDM(object):
"""VDM module for recover random VDM"""
def __init__(self):
self.url = "http://www.viedemerde.fr/aleatoire"
self.vdm = {}
def get(self):
try:
r = requests.get(self.url)
r.encoding = 'utf-8' # ISO-8859-1
if(r.status_code == requests.codes.ok):
parser = MyHTMLParser()
parser.feed(r.text)
self.vdm = parser.getText()
print("Sucess {}".format(r.status_code))
return self.vdm
else:
print("Error {}".format(r.status_code))
except requests.exceptions.ConnectionError as e:
raise errorVDM("network error")
except HTTPError as e:
raise errorVDM("HTTP Error")
class errorVDM(Exception):
def __init__(self, message):
super(errorVDM, self).__init__(message)