From 5e606b21d8f61a65f38f24e6cec5f20e24f7050c Mon Sep 17 00:00:00 2001 From: j Date: Mon, 26 May 2014 00:23:48 +0200 Subject: [PATCH] meta --- oml/meta/worldcat.py | 12 +++++++----- oml/metaremote.py | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/oml/meta/worldcat.py b/oml/meta/worldcat.py index 141ad82..d05a57b 100644 --- a/oml/meta/worldcat.py +++ b/oml/meta/worldcat.py @@ -47,11 +47,13 @@ def lookup(id): key = e.attrib['id'].replace('bibtip_', '') value = e.text_content() data[key] = value - info = doc.xpath('//textarea[@id="util-em-note"]')[0].text - info = dict([i.split(':', 1) for i in info.split('\n\n')[1].split('\n')]) - for key in info: - k = key.lower() - data[k] = info[key].strip() + info = doc.xpath('//textarea[@id="util-em-note"]') + if info: + info = info[0].text + info = dict([i.split(':', 1) for i in info.split('\n\n')[1].split('\n')]) + for key in info: + k = key.lower() + data[k] = info[key].strip() for key in ('id', 'instance', 'mediatype', 'reclist', 'shorttitle'): if key in data: del data[key] diff --git a/oml/metaremote.py b/oml/metaremote.py index 7330919..d59384c 100644 --- a/oml/metaremote.py +++ b/oml/metaremote.py @@ -16,7 +16,7 @@ def request(action, data): }) url = 'http://meta.openmedialibrary.com/api/' try: - return json.loads(read_url(url, data))['data'] + return json.loads(read_url(url, data, timeout=60))['data'] except: return {}