diff --git a/oml/changelog.py b/oml/changelog.py index 9712369..51d0d43 100644 --- a/oml/changelog.py +++ b/oml/changelog.py @@ -161,6 +161,9 @@ class Changelog(db.Model): def action_edititem(self, user, timestamp, itemid, meta): from item.models import Item i = Item.get(itemid) + if not i: + logger.debug('ignore edititem for unknown item %s %s', timestamp, itemid) + return True if i.timestamp > timestamp: logger.debug('ignore edititem change %s %s %s', timestamp, itemid, meta) return True diff --git a/oml/media/__init__.py b/oml/media/__init__.py index 8b1fcf4..3cc0b8f 100644 --- a/oml/media/__init__.py +++ b/oml/media/__init__.py @@ -47,9 +47,19 @@ def metadata(f): if 'isbn' in data: data['primaryid'] = ['isbn', data['isbn'][0]] + if 'author' in data: + if isinstance(data['author'], basestring): + data['author'] = data['author'].split('; ') + if data['author'] in (['Administrator'], ['Default'], ['user']): + del data['author'] if not 'title' in data: data['title'] = os.path.splitext(os.path.basename(f))[0] - if 'author' in data and isinstance(data['author'], basestring): - data['author'] = [data['author']] + if data['title'].startswith('Microsoft Word - '): + data['title'] = data['title'][len('Microsoft Word - '):] + for postfix in ('.doc', 'docx', '.qxd', '.indd'): + if data['title'].endswith(postfix): + data['title'] = data['title'][:-len(postfix)] + if not data['title'].strip(): + del data['title'] return data diff --git a/oml/meta/abebooks.py b/oml/meta/abebooks.py index 3090ed3..7f4b4ed 100644 --- a/oml/meta/abebooks.py +++ b/oml/meta/abebooks.py @@ -38,7 +38,12 @@ def lookup(id): doc = lxml.html.document_fromstring(html) for e in doc.xpath("//*[contains(@id, 'biblio')]"): key = e.attrib['id'].replace('biblio-', '') - value = e.text_content() + value = e.text_content().strip() + k = keys.get(key, key) + if k == 'date' and value == 'Publication Date:': + value = '' + elif k == 'publisher' and value == 'Publisher:': + value = '' if value and key not in ('bookcondition', 'binding', 'edition-amz'): - data[keys.get(key, key)] = value + data[k] = value return data diff --git a/oml/meta/lookupbyisbn.py b/oml/meta/lookupbyisbn.py index 00476ad..2bfaff4 100644 --- a/oml/meta/lookupbyisbn.py +++ b/oml/meta/lookupbyisbn.py @@ -50,6 +50,8 @@ def lookup(id): url = '%s/Lookup/Book/%s/%s/1' % (base, id, id) data = read_url(url).decode('utf-8') r["title"] = find_re(data, "