home | list info | list archive | date index | thread index

Re: [OCLUG-Tech] symbolic links

On Friday 17 April 2009 3:02:07 pm Michael Walma wrote:
> Hi Bruce,
>
> If I understand you correctly, the name of the image files are the
> current ISBN 10 and you want to rename the files to the correct ISBN 13
> while retaining a symbolic link named the ISBN 10?
>
> That actually would not be that hard to do with a perl script if you
> know the algorithm for calculating the checksum digit that is the last
> digit of the ISBN 13, which I just found on wikipedia.  If you are not
> in a rush, I could do it for you in the next week of so in my spare
> time.  If you want to try it, it would look something like
>
> nine_digits = substring(isbn10, 0, 8)
> twelve_digits = concat( "978", nine_digits)
> 13th_digit = calculate_checksum( twelve_digits)
> isbn13 = concat(twelve_digits, 13th_digit)
> ln -s isbn10 isbn13
>
> If the files are to remain on the same filesystem, you could also use
> hard links instead of symbolic links.
>
> Michael
>
> Bruce Harding wrote:
> > I'm slowly working to move our website 13 ISBN compatible.  I've got a
> > directory with 20,000 plus images.  Most of those are 10 digit ISBNs.  I
> > want to convert them all to 13 ISBN.   My web programmer wants me to
> > retain a symbolic link to retain 10 digit ISBN name to avoid breaking
> > anything in his progamming that is hardcode.
> >
> > I googled for this and all that I'm finding is man page kind of thing.  I
> > makes me think this is not possilbe?
> >
> > Any suggestions.

Michael, 

No not to much of a hurry.  Right all images prior to mid-2008 are named with 
there 10 digit ISBN.

I found this attached script as well.  Also find this one below.


	

def check_digit_10(isbn):
    assert len(isbn) == 9
    sum = 0
    for i in range(len(isbn)):
        c = int(isbn[i])
        w = i + 1
        sum += w * c
    r = sum % 11
    if r == 10: return 'X'
    else: return str(r)

def check_digit_13(isbn):
    assert len(isbn) == 12
    sum = 0
    for i in range(len(isbn)):
        c = int(isbn[i])
        if i % 2: w = 3
        else: w = 1
        sum += w * c
    r = 10 - (sum % 10)
    if r == 10: return '0'
    else: return str(r)

def convert_10_to_13(isbn):
    assert len(isbn) == 10
    prefix = '978' + isbn[:-1]
    check = check_digit_13(prefix)
    return prefix + check



-- 
Bruce Harding, Member: IEEE, SPIE, IACR
Manager,
Computer Books for Less
210 Bank St.
Ottawa ON  K2P 1W2
Phone: 613-233-7357
Fax: 613-233-6823

replies

references

message navigation