mirror of
https://github.com/RussellChamp/tilde-projects.git
synced 2026-10-28 00:22:34 +00:00
Add files I forgot
This commit is contained in:
1 parent
5f1bf146c3
commit
772995c0ff
29 files changed
+1807
No files matched your search
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/python3
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
import random
|
||||
|
||||
|
||||
def define(word):
|
||||
defs = []
|
||||
url = "http://www.merriam-webster.com/dictionary/{}".format(word)
|
||||
soup = BeautifulSoup(requests.get(url).content, "html.parser")
|
||||
head = soup.find("div", id="headword")
|
||||
if head:
|
||||
for p in head.find_all("p"):
|
||||
defs.append(p.text)
|
||||
return defs
|
||||
|
||||
|
||||
key = open("/home/krowbar/.secret/key").readline().rstrip()
|
||||
|
||||
|
||||
def defWord(word, short=True):
|
||||
defs = []
|
||||
url = "http://www.dictionaryapi.com/api/v1/references/collegiate/xml/{}?key={}".format(
|
||||
word, key
|
||||
)
|
||||
soup = BeautifulSoup(requests.get(url).content, "html5lib")
|
||||
entry = soup.find("entry")
|
||||
if entry:
|
||||
for d in entry.find_all("dt"):
|
||||
defs.append(d.text)
|
||||
if short:
|
||||
return " ".join(defs)
|
||||
else:
|
||||
return defs
|
||||
Reference in new issue
Block a user