Skip to content

Commit 5bcb39c

Browse files
authored
Merge pull request CloudBotIRC#148 from linuxdaemon/gonzobot+etymology-fix
Fix etymology.py
2 parents b06d6eb + 8c66575 commit 5bcb39c

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

plugins/etymology.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
# Plugin by GhettoWizard and Scaevolus
1+
"""
2+
Etymology plugin
3+
4+
Authors:
5+
- GhettoWizard
6+
- Scaevolus
7+
- linuxdaemon <[email protected]>
8+
"""
9+
import re
210

311
import requests
4-
from lxml import html
12+
from bs4 import BeautifulSoup
513
from requests import HTTPError
614

715
from cloudbot import hook
@@ -26,14 +34,16 @@ def etymology(text, reply):
2634
if response.status_code != requests.codes.ok:
2735
return "Error reaching etymonline.com: {}".format(response.status_code)
2836

29-
h = html.fromstring(response.text)
37+
soup = BeautifulSoup(response.text, "lxml")
3038

31-
etym = h.xpath('//dl')
39+
block = soup.find('div', class_=re.compile("word--.+"))
3240

33-
if not etym:
41+
if not block:
3442
return 'No etymology found for {} :('.format(text)
3543

36-
etym = etym[0].text_content()
44+
etym = ' '.join(e.text for e in block.div)
45+
46+
etym = ' '.join(etym.splitlines())
3747

3848
etym = ' '.join(etym.split())
3949

0 commit comments

Comments
 (0)