Word Definitions (commandline Application)

Get definitions for any word using the commandline.

This script is almost the same as the Synonyms script.
(look for more info there)

 lxer@server:~$  ./definition.py python
Overview of noun python
The noun python has 3 senses? (first 1 from tagged texts)
1. (3) python (large Old World boas)

2. python (a soothsaying spirit or a person who is possessed by such a spirit)

3. Python ((Greek mythology) dragon killed by Apollo at Delphi)

 

#!/usr/bin/python

# get synonyms for any word from synonym.com
# uses python + beautifulsoup

import re, urllib, sys
from BeautifulSoup import BeautifulSoup

if (len(sys.argv) > 1):
word = sys.argv[1]
else:
print " usage: synon word"
exit(0)

url = "http://www.synonym.com/definition/"+word
f = urllib.urlopen(url)
doc = f.read()

soup = BeautifulSoup(''.join(doc))

def strip_tags(value):
return re.sub(r'<[^>]*?>', '', value)

divs = soup.findAll('div')
result = str(divs[9])
result = result.replace("<br />", "\n")
result = strip_tags(result)
#remove empty lines
a = result.split('\n')
for b in a:
if b:
print b

Post your comment

Comments

No one has commented on this page yet.

RSS feed for comments on this page | RSS feed for all comments