This commit is contained in:
Ben Harris committed 2018-10-09 02:50:10 -04:00
1 parent a8a5de36f2
commit 58753c7234
38 files changed
+4549 -2523

No files matched your search

+22 -16
View File
@@ -1,28 +1,34 @@
import urllib
from bs4 import BeautifulSoup
import random
def define(word):
defs = []
url = 'http://www.merriam-webster.com/dictionary/%s' % word
soup = BeautifulSoup(urllib.urlopen(url).read(), 'html.parser')
head = soup.find('div', id='headword')
if head:
for p in head.find_all('p'):
defs.append(p.text.encode('ascii', 'ignore'))
return defs
defs = []
url = "http://www.merriam-webster.com/dictionary/%s" % word
soup = BeautifulSoup(urllib.urlopen(url).read(), "html.parser")
head = soup.find("div", id="headword")
if head:
for p in head.find_all("p"):
defs.append(p.text.encode("ascii", "ignore"))
return defs
key = open("/home/krowbar/.secret/key").readline().rstrip()
def defWord(word, short = True):
def defWord(word, short=True):
defs = []
url = 'http://www.dictionaryapi.com/api/v1/references/collegiate/xml/%s?key=%s' % (word, key)
soup = BeautifulSoup(urllib.urlopen(url).read(), 'html5lib')
entry = soup.find('entry')
url = "http://www.dictionaryapi.com/api/v1/references/collegiate/xml/%s?key=%s" % (
word,
key,
)
soup = BeautifulSoup(urllib.urlopen(url).read(), "html5lib")
entry = soup.find("entry")
if entry:
for d in entry.find_all('dt'):
defs.append(d.text.encode('ascii', 'ignore'))
for d in entry.find_all("dt"):
defs.append(d.text.encode("ascii", "ignore"))
if short:
return ' '.join(defs)
return " ".join(defs)
else:
return defs