Skip to content

Commit d68427c

Browse files
committed
Fix etymology.py
1 parent 9bfdbca commit d68427c

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,12 +1,20 @@
1-
# Plugin by GhettoWizard and Scaevolus
1+
"""
2+
Etymology plugin
23
3-
from lxml import html
4+
Authors:
5+
- GhettoWizard
6+
- Scaevolus
7+
- linuxdaemon <[email protected]>
8+
"""
9+
import re
410

511
import requests
12+
from bs4 import BeautifulSoup
613
from requests import HTTPError
714

815
from cloudbot import hook
916

17+
1018
@hook.command("e", "etymology")
1119
def etymology(text, reply):
1220
"""<word> - retrieves the etymology of <word>
@@ -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)