summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Robinson <joe@mumsnet.com>2014-09-23 16:36:52 +0100
committerJoe Robinson <joe@mumsnet.com>2014-09-23 16:36:52 +0100
commit9b9606137f48284aae9918b04769d7485d417239 (patch)
tree8c8f9c41cf5d3589f4d1e75e45a55391f23166be
parent9d6a2b3992693a10b2cd3feb43d8e92dda718943 (diff)
Added error checking for JSON parsing
-rwxr-xr-xbladictionary.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/bladictionary.py b/bladictionary.py
index 7a3112a..c3ee7db 100755
--- a/bladictionary.py
+++ b/bladictionary.py
@@ -8,7 +8,7 @@ from lxml import etree
import sqlite3
import requests
-VERSION = "2.3.2"
+VERSION = "2.3.3"
class Definition(object):
#ID is relative to the word type, eg noun 1, noun 2, verb 1, verb 2, not to the entire list
@@ -426,13 +426,17 @@ def parse_foldoc(word, refer = None):
return items
def parse_urban(word):
- r = requests.get("http://urbanscraper.herokuapp.com/search/" + word)
- json = r.json()
+ try:
+ r = requests.get("http://urbanscraper.herokuapp.com/search/" + word)
+ json = r.json()
+ except:
+ #Should probably print an error, but then that would break printing other definitions, so let's not
+ return
items = []
id = 1
-
for json_item in json:
+ print json_item
if json_item['definition'] != "" and json_item['definition'] is not None:
item = Definition(word, id, "urban", "urban", json_item['definition'], [json_item['example']], [], [])
items.append(item)