diff options
author | Joe Robinson <joe@mumsnet.com> | 2014-09-16 14:57:17 +0100 |
---|---|---|
committer | Joe Robinson <joe@mumsnet.com> | 2014-09-16 14:57:17 +0100 |
commit | adc06d3e9905fcde60d90134f3e4a38241d54546 (patch) | |
tree | 947c46fde541b3983bda129b1eb72d1e48701320 /bladictionary.py | |
parent | d0e39099b8d287e9a2c070717dbba81c296442ac (diff) |
Add error checking for if the API is down
Diffstat (limited to 'bladictionary.py')
-rw-r--r-- | bladictionary.py | 12 |
1 files 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) |