From 63b2b0a861bc5135227aae9f98823169fd419ddf Mon Sep 17 00:00:00 2001 From: Arthur de Jong Date: Mon, 20 Jun 2011 20:56:39 +0000 Subject: implement a conversion function from ISSN to EAN git-svn-id: http://arthurdejong.org/svn/python-stdnum/python-stdnum@72 9dea7c4f-944c-4273-ac1a-574ede026edc --- stdnum/issn.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'stdnum/issn.py') diff --git a/stdnum/issn.py b/stdnum/issn.py index 4f879c4..4b5412e 100644 --- a/stdnum/issn.py +++ b/stdnum/issn.py @@ -28,8 +28,12 @@ False '00321478' >>> format('00249319') '0024-9319' +>>> to_ean('0264-3596') +'9770264359008' """ +from stdnum import ean + def compact(number): """Convert the ISSN to the minimal representation. This strips the number @@ -58,3 +62,9 @@ def format(number): """Reformat the passed number to the standard format.""" number = compact(number) return number[:4] + '-' + number[4:] + +def to_ean(number, issue_code='00'): + """Convert the number to EAN-13 format. The number is assumed to be a + valid ISSN.""" + number = '977' + compact(number)[:-1] + issue_code + return number + ean.calc_check_digit(number) -- cgit v1.2.3