lists.arthurdejong.org
RSS feed

python-stdnum commit: r72 - python-stdnum/stdnum

[Date Prev][Date Next] [Thread Prev][Thread Next]

python-stdnum commit: r72 - python-stdnum/stdnum



Author: arthur
Date: Mon Jun 20 22:56:39 2011
New Revision: 72
URL: http://arthurdejong.org/viewvc/python-stdnum?view=rev&revision=72

Log:
implement a conversion function from ISSN to EAN

Modified:
   python-stdnum/stdnum/issn.py

Modified: python-stdnum/stdnum/issn.py
==============================================================================
--- python-stdnum/stdnum/issn.py        Mon Jun 20 22:55:58 2011        (r71)
+++ python-stdnum/stdnum/issn.py        Mon Jun 20 22:56:39 2011        (r72)
@@ -28,8 +28,12 @@
 '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 @@
     """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)
-- 
To unsubscribe send an email to
python-stdnum-commits-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/python-stdnum-commits