-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy path__init__.py
More file actions
29 lines (24 loc) · 927 Bytes
/
__init__.py
File metadata and controls
29 lines (24 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# -*- coding: utf-8 -*-
import re
import urllib
from BeautifulSoup import BeautifulSoup
from pipobot.lib.modules import SyncModule, defaultcmd
from pipobot.lib.utils import xhtml2text
class CmdSosBides(SyncModule):
def __init__(self, bot):
desc = "sos_bides : Fait appel à une superbe blague pour passer inaperçu"
SyncModule.__init__(self,
bot,
desc=desc,
name="sos_bides")
@defaultcmd
def answer(self, sender, message):
url = urllib.urlopen("http://www.blablagues.net/hasard.html")
soup = BeautifulSoup(url.read())
html = soup.find("div", {"class": "blague"}).findAll("div")
res = u""
for div in html:
res += u"\n" + div.renderContents()
res = re.sub(u"<br />\r\n", u"\n", res)
res = re.sub(u"<[^>]*>", "", res)
return res.strip()