30 lines
630 B
Python
30 lines
630 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 ConnectionError as e:
|
|
print("Connection error {}".format(e))
|
|
|
|
|