File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- # Plugin by GhettoWizard and Scaevolus
1+ """
2+ Etymology plugin
3+
4+ Authors:
5+ - GhettoWizard
6+ - Scaevolus
7+ 8+ """
9+ import re
210
311import requests
4- from lxml import html
12+ from bs4 import BeautifulSoup
513from requests import HTTPError
614
715from 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
You can’t perform that action at this time.
0 commit comments