no empty values

This commit is contained in:
j 2015-12-01 12:32:42 +01:00
parent dcb0a16153
commit 72ed51881b

View file

@ -47,7 +47,8 @@ def lookup(id):
doc = lxml.html.document_fromstring(html) doc = lxml.html.document_fromstring(html)
for e in doc.xpath("//*[contains(@id, 'bibtip')]"): for e in doc.xpath("//*[contains(@id, 'bibtip')]"):
key = e.attrib['id'].replace('bibtip_', '') key = e.attrib['id'].replace('bibtip_', '')
value = e.text_content() value = e.text_content().strip()
if value:
data[key] = value data[key] = value
info = doc.xpath('//textarea[@id="util-em-note"]') info = doc.xpath('//textarea[@id="util-em-note"]')
if info: if info:
@ -55,7 +56,9 @@ def lookup(id):
info = dict([i.split(':', 1) for i in info.split('\n\n')[1].split('\n')]) info = dict([i.split(':', 1) for i in info.split('\n\n')[1].split('\n')])
for key in info: for key in info:
k = key.lower() k = key.lower()
data[k] = info[key].strip() value = info[key].strip()
if value:
data[k] = value
for key in ('id', 'instance', 'mediatype', 'reclist', 'shorttitle'): for key in ('id', 'instance', 'mediatype', 'reclist', 'shorttitle'):
if key in data: if key in data:
del data[key] del data[key]
@ -98,6 +101,11 @@ def lookup(id):
if m: if m:
data['date'] = m[0] data['date'] = m[0]
if 'place' in data:
if data['place'][0].startswith('['):
data['place'] = [data['place'][0][1:]]
if data['place'][0].endswith(']'):
data['place'] = [data['place'][0][:-1]]
logger.debug('lookup %s => %s', id, list(data.keys())) logger.debug('lookup %s => %s', id, list(data.keys()))
return data return data