2016-07-10 16:40:50 +00:00
|
|
|
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))
|
|
|
|
|
2016-07-23 16:51:12 +00:00
|
|
|
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)
|
|
|
|
|