-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0a986d
commit 65bab6c
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
|
||
|