This commit is contained in:
j 2014-05-16 10:06:11 +02:00
commit e41942ea99
28 changed files with 240 additions and 84 deletions

View file

@ -1,5 +1,16 @@
import re
import stdnum.isbn
def normalize_isbn(value):
return ''.join([s for s in value if s.isdigit() or s == 'X'])
def find_isbns(text):
matches = re.compile('\d[\d\-X\ ]+').findall(text)
matches = [normalize_isbn(value) for value in matches]
return [isbn for isbn in matches if stdnum.isbn.is_valid(isbn)
and len(isbn) in (10, 13)
and isbn not in (
'0' * 10,
'0' * 13,
)]