From 9b9606137f48284aae9918b04769d7485d417239 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Tue, 23 Sep 2014 16:36:52 +0100 Subject: Added error checking for JSON parsing --- bladictionary.py | 12 ++++++++---- 1 file 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) -- cgit v1.2.3