From adc06d3e9905fcde60d90134f3e4a38241d54546 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Tue, 16 Sep 2014 14:57:17 +0100 Subject: Add error checking for if the API is down --- bladictionary.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/bladictionary.py b/bladictionary.py index df5d0fc..cbe6b22 100644 --- a/bladictionary.py +++ b/bladictionary.py @@ -1,5 +1,5 @@ import requests -from lxml import etree as ET +from lxml import etree version = "2.0.1b" class Definition(object): @@ -21,7 +21,11 @@ class Definition(object): def get_xml(): api_url = "http://services.aonaware.com/DictService/DictService.asmx/DefineInDict?dictId=wn&word=red" - xml = ET.parse("http://services.aonaware.com/DictService/DictService.asmx/DefineInDict?dictId=wn&word=red") + try: + xml = etree.parse("http://services.aonaware.com/DictService/DictService.asmx/DefineInDict?dictId=wn&word=red") + except IOError: + print "Error: Could not access the Dictionary service." + return #Root element tag is WordDefinition, which is the same as the element which contains the definition #That's akward, so let's just @@ -119,9 +123,11 @@ def parse_xml(xml): def main(): - print "test" xml = get_xml() + if xml is None: + return + items = parse_xml(xml) print len(items) -- cgit v1.2.3