summaryrefslogtreecommitdiff
path: root/bladictionary.py
diff options
context:
space:
mode:
Diffstat (limited to 'bladictionary.py')
-rwxr-xr-xbladictionary.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/bladictionary.py b/bladictionary.py
index c4dd1d8..42121a4 100755
--- a/bladictionary.py
+++ b/bladictionary.py
@@ -9,7 +9,7 @@ import sqlite3
import requests
from definition import Definition
-VERSION = "2.4.4"
+VERSION = "2.5.0"
def get_xml(word, word_dict):
api_url = "http://services.aonaware.com/DictService/DictService.asmx/DefineInDict?dictId="+word_dict+"&word="+word
@@ -322,7 +322,7 @@ def parse_urban(word):
word = word.replace(" ", "+")
try:
- r = requests.get("http://urbanscraper.herokuapp.com/search/" + word)
+ r = requests.get("http://api.urbandictionary.com/v0/define?term=" + word)
json = r.json()
except:
#Should probably print an error, but then that would break printing other definitions, so let's not
@@ -330,9 +330,9 @@ def parse_urban(word):
items = []
id = 1
- for json_item in json:
+ for json_item in json['list']:
if json_item['definition']:
- item = Definition(word, id, "urban", "urban", json_item['definition'], [json_item['example']], [], [])
+ item = Definition(word, id, "urban", "urban", json_item['definition'], [json_item['example'].replace("\r\n", " ")], [], [])
items.append(item)
id += 1
@@ -359,17 +359,20 @@ def main():
elif word_dict == "foldoc" or word_type == "tech":
items = get_sql(word, "foldoc")
elif word_dict == "urban":
- print "Urban dictionary API is currently down :("
- sys.exit( 0 )
+ items = parse_urban(word)
else:
if word_dict is None or word_dict == "":
word_dict = "wn"
items = get_sql(word, "wn")
-
+
foldoc_items = get_sql(word, "foldoc")
if foldoc_items is not None and len(foldoc_items) > 0:
items += foldoc_items
+ urban_items = parse_urban(word)
+ if urban_items is not None and len(urban_items) > 0:
+ items += urban_items
+
if items is None or len(items) == 0:
print "No definitions found for "+word
sys.exit( 1 )