Module:Format ISBN/data/doc

Python script to update this data module
&#x3c;syntaxhighlight lang="python"&#x3e;
 * 1) !/usr/bin/env python


 * 1) This work has been released into the public domain by its author, User:Cobaltcigs.
 * 2) This applies worldwide.  In some countries this may not be legally possible; if so:
 * 3) User:Cobaltcigs grants anyone the right to use this work for any purpose, without any
 * 4) conditions, unless such conditions are required by law.

import xml.dom.minidom import urllib2

url = "https://www.isbn-international.org/export_rangemessage.xml" req = urllib2.Request(url) response = urllib2.urlopen(req) xmlTxt = response.read

f = open("RangeMessage.xml", "w") f.write(xmlTxt) f.close

document = xml.dom.minidom.parseString(xmlTxt)

source = document.getElementsByTagName("MessageSource")[0].firstChild.nodeValue version = document.getElementsByTagName("MessageSerialNumber")[0].firstChild.nodeValue timestamp = document.getElementsByTagName("MessageDate")[0].firstChild.nodeValue

print("--") print("""\tGenerated from %s's RangeMessage.xml file at: \t\t%s \tusing a script. \tVersion: %s (%s)""" % (source, url, version, timestamp)) print("""\tNotes: \t* Integer tuples at right represent the middle three (of five) digit-group quantities \t for any ISBN in the specified (quasi-numeric but actually lexicographical) range. \t* The "specified range" for the tuple specified on row[N] can be thought of as any \t  ISBN Q where (Q &")

print("return {") for p in document.getElementsByTagName("Prefix"): pp = p.firstChild.nodeValue.split("-") if len(pp) != 2: continue prefix = "".join(pp) n1 = len(pp[0]) n2 = len(pp[1]) for q in p.parentNode.getElementsByTagName("Rule"): end = (prefix + q.getElementsByTagName("Range")[0].firstChild.nodeValue.split("-")[1]+"9"*9)[:13] n3 = int(q.getElementsByTagName("Length")[0].firstChild.nodeValue) # disregard (yet unallocated?) blocks where (publisher identifier's) &#x3c;Length&#x3e;0&#x3c;/Length&#x3e; if n3 == 0: continue n4 = 12-(n1+n2+n3) # check digit length not mathematically needed here print('\t{"%s", {%s,%s,%s}},' % (end,n2,n3,n4)) print("\t}") &#x3c;/syntaxhighlight&#x3e;
 * 1) 		n5 = 1