Skip to content

Commit

Permalink
Isolate stuffS
Browse files Browse the repository at this point in the history
  • Loading branch information
nootanghimire committed Jan 20, 2018
1 parent a0a986d commit 65bab6c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/sources/Exceptions/NoResultException.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class NoResultException(Exception):
def __init__(self, message):
self.messge = message

def __str__(self):
return self.message

22 changes: 22 additions & 0 deletions src/sources/UrbanDictionary/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import requests
#import NotFoundException

class UrbanDictionary(object):
def __init__(self):
self._name = 'Urban Dictionary'
self._apiBaseUrl = 'http://api.urbandictionary.com/v0/define?term='

def getMeaning(self, term):
callUrl = self._apiBaseUrl + term
result = requests.get(callUrl)
try:
answer = result.json()
except ValueError:
# @todo: log this in future
raise NotFoundException('We could not find the term')
if not answer["list"]:
raise NotFoundException('We could not find the term')

return answer["list"][0]["definition"]


0 comments on commit 65bab6c

Please sign in to comment.