diff options
-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) |