Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 2 additions & 3 deletions PyDictionary/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
__author__ = "Pradipta Bora"
__version__ = "1.5.1"
__version__ = "2.0.2"

try:
from .core import *
except:
except ImportError:
from core import *

34 changes: 11 additions & 23 deletions PyDictionary/core.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import print_function
import sys, re, goslate
import sys
import re
try:
from .utils import _get_soup_object
except:
Expand All @@ -9,6 +10,7 @@
if list(sys.version_info)[0] == 2:
python2 = True


class PyDictionary(object):

def __init__(self, *args):
Expand All @@ -20,7 +22,6 @@ def __init__(self, *args):
except:
self.args = args


def printMeanings(self):
dic = self.getMeanings()
for key in dic.keys():
Expand All @@ -31,13 +32,13 @@ def printMeanings(self):
print(m)

def printAntonyms(self):
antonyms = dict(zip(self.args,self.getAntonyms(False)))
antonyms = dict(zip(self.args, self.getAntonyms(False)))
for word in antonyms:
print(word+':')
print(', '.join(antonyms[word]))

def printSynonyms(self):
synonyms = dict(zip(self.args,self.getSynonyms(False)))
synonyms = dict(zip(self.args, self.getSynonyms(False)))
for word in synonyms:
print(word+':')
print(', '.join(synonyms[word]))
Expand All @@ -48,20 +49,6 @@ def getMeanings(self):
out[term] = self.meaning(term)
return out

def translateTo(self, language):
return [self.translate(term, language) for term in self.args]

def translate(self, term, language):
if len(term.split()) > 1:
print("Error: A Term must be only a single word")
else:
try:
gs = goslate.Goslate()
word = gs.translate(term, language)
return word
except:
print("Invalid Word")

def getSynonyms(self, formatted=True):
return [self.synonym(term, formatted) for term in self.args]

Expand All @@ -83,7 +70,8 @@ def synonym(term, formatted=False):
print("Error: A Term must be only a single word")
else:
try:
data = _get_soup_object("https://www.synonym.com/synonyms/{0}".format(term))
data = _get_soup_object(
"https://www.synonym.com/synonyms/{0}".format(term))
section = data.find('div', {'class': 'type-synonym'})
spans = section.findAll('a')
synonyms = [span.text.strip() for span in spans]
Expand All @@ -93,14 +81,14 @@ def synonym(term, formatted=False):
except:
print("{0} has no Synonyms in the API".format(term))


@staticmethod
def antonym(term, formatted=False):
if len(term.split()) > 1:
print("Error: A Term must be only a single word")
else:
try:
data = _get_soup_object("https://www.synonym.com/synonyms/{0}".format(term))
data = _get_soup_object(
"https://www.synonym.com/synonyms/{0}".format(term))
section = data.find('div', {'class': 'type-antonym'})
spans = section.findAll('a')
antonyms = [span.text.strip() for span in spans]
Expand Down Expand Up @@ -137,7 +125,7 @@ def meaning(term, disable_errors=False):
if disable_errors == False:
print("Error: The Following Error occured: %s" % e)


if __name__ == '__main__':
d = PyDictionary('honest','happy')
d = PyDictionary('honest', 'happy')
d.printSynonyms()

7 changes: 3 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
long_description = fh.read()

setuptools.setup(
name="PyDictionary", # Replace with your own username
version="2.0.1",
name="PyDictionary", # Replace with your own username
version="2.0.2",
author="geekpradd",
author_email="pradd@outlook.com",
description="A real dictionary module for Python",
Expand All @@ -20,7 +20,6 @@
install_requires=[
'bs4',
'click',
'goslate',
'requests'
]
)
)