Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibly un necessary PR #48

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions PyDictionary/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ def translateTo(self, language):
def translate(self, term, language):
if len(term.split()) > 1:
print("Error: A Term must be only a single word")
raise OneWordOnly
else:
try:
gs = goslate.Goslate()
word = gs.translate(term, language)
return word
except:
print("Invalid Word")
raise InvalidWord

def getSynonyms(self, formatted=True):
return [self.synonym(term, formatted) for term in self.args]
Expand All @@ -80,7 +81,7 @@ def getAntonyms(self, formatted=True):
@staticmethod
def synonym(term, formatted=False):
if len(term.split()) > 1:
print("Error: A Term must be only a single word")
raise OneWordOnly
else:
try:
data = _get_soup_object("https://www.synonym.com/synonyms/{0}".format(term))
Expand All @@ -91,13 +92,13 @@ def synonym(term, formatted=False):
return {term: synonyms}
return synonyms
except:
print("{0} has no Synonyms in the API".format(term))
raise NoSynonyms


@staticmethod
def antonym(term, formatted=False):
if len(term.split()) > 1:
print("Error: A Term must be only a single word")
raise TooManyWords
else:
try:
data = _get_soup_object("https://www.synonym.com/synonyms/{0}".format(term))
Expand All @@ -108,12 +109,12 @@ def antonym(term, formatted=False):
return {term: antonyms}
return antonyms
except:
print("{0} has no Antonyms in the API".format(term))
raise NoResults

@staticmethod
def meaning(term, disable_errors=False):
if len(term.split()) > 1:
print("Error: A Term must be only a single word")
raise TooManyWords
else:
try:
html = _get_soup_object("http://wordnetweb.princeton.edu/perl/webwn?s={0}".format(
Expand All @@ -135,7 +136,7 @@ def meaning(term, disable_errors=False):
return out
except Exception as e:
if disable_errors == False:
print("Error: The Following Error occured: %s" % e)
raise e

if __name__ == '__main__':
d = PyDictionary('honest','happy')
Expand Down