diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2011-06-20 22:56:39 +0200 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2011-06-20 22:56:39 +0200 |
commit | 63b2b0a861bc5135227aae9f98823169fd419ddf (patch) | |
tree | b0546b60992c5c1d475be65e44cb026a2d37ace0 /stdnum/issn.py | |
parent | d101acfb563b495c0a38037c683980b91fe43259 (diff) |
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
Diffstat (limited to 'stdnum/issn.py')
-rw-r--r-- | stdnum/issn.py | 10 |
1 files changed, 10 insertions, 0 deletions
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) |