Example #1
0
 def test_hyphenating_known_values_not_unicode(self):
     for with_hyphens in self.knownValues:
         without_hyphens = with_hyphens.replace('-', '')
         without_hyphens_ascii = without_hyphens.encode("ascii")
         self.assertEqual(
             isbn_hyphenate.hyphenate(without_hyphens_ascii),
             with_hyphens.encode("ascii"))
Example #2
0
def _hyphenateIsbnNumber(match):
    """Helper function to deal with a single ISBN."""
    isbn = match.group('code')
    isbn = isbn.upper()
    try:
        is_valid(isbn)
    except InvalidIsbnException:
        return isbn

    try:
        stdnum.isbn
    except NameError:
        pass
    else:
        i = stdnum.isbn.format(isbn)
        return i

    try:
        isbn_hyphenate
    except NameError:
        pass
    else:
        try:
            i = isbn_hyphenate.hyphenate(isbn)
        except (isbn_hyphenate.IsbnMalformedError,
                isbn_hyphenate.IsbnUnableToHyphenateError):
            return isbn
        return i

    i = getIsbn(isbn)
    i.format()
    return i.code
Example #3
0
def _hyphenateIsbnNumber(match):
    """Helper function to deal with a single ISBN."""
    isbn = match.group('code')
    isbn = isbn.upper()
    try:
        is_valid(isbn)
    except InvalidIsbnException:
        return isbn

    try:
        stdnum.isbn
    except NameError:
        pass
    else:
        i = stdnum.isbn.format(isbn)
        return i

    try:
        isbn_hyphenate
    except NameError:
        pass
    else:
        try:
            i = isbn_hyphenate.hyphenate(isbn)
        except (isbn_hyphenate.IsbnMalformedError,
                isbn_hyphenate.IsbnUnableToHyphenateError):
            return isbn
        return i

    i = getIsbn(isbn)
    i.format()
    return i.code
Example #4
0
 def sanitise_isbn(isbn):
     """Return a hyphenated ISBN"""
     if not isbn:
         return None
     try:
         if "-" in str(isbn):
             return str(isbn)
         return isbn_hyphenate.hyphenate(str(int(isbn)))
     except isbn_hyphenate.IsbnMalformedError:
         print(isbn)
         raise
Example #5
0
def parse(input):
    """Parse the input data."""

    for i in input:
        if i["translators"] == "n/a":
            del i["translators"]
        if i["url"] == 'unknown':
            del i["url"]

        i.update(isbn=hyphenate(i["isbn"]))

    env = Environment(autoescape=False)
    templ = env.from_string(TEMPLATE)

    return templ.render(books=input)
Example #6
0
 def test_hyphenating_known_values_not_unicode(self):
     for with_hyphens in self.knownValues:
         without_hyphens = with_hyphens.replace('-', '')
         without_hyphens_ascii = without_hyphens.encode("ascii")
         self.assertEqual(isbn_hyphenate.hyphenate(without_hyphens_ascii), with_hyphens.encode("ascii"))
Example #7
0
 def test_hyphenating_known_values(self):
     for with_hyphens in self.knownValues:
         without_hyphens = with_hyphens.replace('-', '')
         self.assertEqual(isbn_hyphenate.hyphenate(without_hyphens), with_hyphens)
Example #8
0
def main():
    #Commnd line arguments
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '-path',
        '--GCIS',
        help=
        "Insert url path to GCIS book in JSON format [ex.'https://gcis-search-stage.jpl.net:3000/book.json?all=1'] "
    )
    args = parser.parse_args()
    GCIS = args.GCIS

    if GCIS is None:
        GCIS = 'https://gcis-search-stage.jpl.net:3000/book.json?all=1'
        print(
            'NO MANUAL GCIS PATH\n ALL GCIS BOOK JSON FORMATS WILL BE USED AS DEFAULT'
        )

    GCISPAR = parse(GCIS)
    for x in range(len(GCISPAR)):
        try:
            #Extracts book identifier from GCIS#
            IDEN = GCISPAR[x]["identifier"]
            match = re.search(r'.*/(.*?)\..*?$', GCIS)
            if match:
                FILETYPE = match.groups()[0]
        #HREF = url that leads to book.json in GCIS-DEV
            HREF = 'https://gcis-search-stage.jpl.net:3000/{}/{}.json'.format(
                FILETYPE, IDEN)
            HREFPAR = parse(HREF)
            #Extracts book title and isbn from GCIS-DEV
            d = dict(HREFPAR)
            TITLE = d['title']
            ISBNS = d['isbn']
            #Cleans ISBNS to only conatian valid characters
            CISBN = clean(ISBNS)
            #V13 = validated canonical ISBN-13
            V13 = EAN13(CISBN)
            if V13 is None:
                V13 = canonical(CISBN)
            M = parse(HREF)

            print("GCIS-DEV\n\n\t", M, '\n\n\t', "isbn_original:", ISBNS,
                  '\n\n\t', "isbn_mod:", V13, "\n\n")

            #DBpedia ISBN formats
            a = ISBNS
            b = canonical(CISBN)
            c = to_isbn10(CISBN)
            d = hyphenate(to_isbn10(CISBN))
            e = to_isbn13(CISBN)
            f = hyphenate(to_isbn13(CISBN))
            g = V13
            h = "ISBN {}".format(CISBN)
            i = "ISBN {}".format(canonical(CISBN))
            j = "ISBN {}".format(hyphenate(to_isbn13(CISBN)))
            k = "ISBN {}".format(V13)
            l = "ISBN {}".format(to_isbn10(CISBN))
            m = "ISBN {}".format(hyphenate(to_isbn10(CISBN)))

            tests = [a, b, c, d, e, f, g, h, i, j, k, l, m]

            for indie in tests:
                r = QUERY % indie
                RQUERY(r)
                if len(RQUERY(r)) != 0:
                    print(RQUERY(r))
                    break

        except:
            Error = '\n\t######## PROBLEM #######\n\tTitle:{}\n\tGCIS-ISBN:{}\n\tIdentifier:{}\n\n'.format(
                TITLE, ISBNS, IDEN)
            print(Error)
            file.write(Error)
def main():
#Commnd line arguments
    parser = argparse.ArgumentParser()
    parser.add_argument('-path', '--GCIS', help = "Insert url path to GCIS book in JSON format [ex.'https://gcis-search-stage.jpl.net:3000/book.json?all=1'] ")
    args = parser.parse_args()
    GCIS = args.GCIS

    if GCIS is None:
        GCIS = 'https://gcis-search-stage.jpl.net:3000/book.json?all=1'
        print('NO MANUAL GCIS PATH\n ALL GCIS BOOK JSON FORMATS WILL BE USED AS DEFAULT')

    GCISPAR = parse(GCIS)
    for x in range(len(GCISPAR)):
        try:
        #Extracts book identifier from GCIS#
            IDEN = GCISPAR[x]["identifier"]
            match =  re.search(r'.*/(.*?)\..*?$', GCIS)
            if match:
                FILETYPE = match.groups()[0]
        #HREF = url that leads to book.json in GCIS-DEV
            HREF = 'https://gcis-search-stage.jpl.net:3000/{}/{}.json' .format(FILETYPE,IDEN)
            HREFPAR = parse(HREF)
        #Extracts book title and isbn from GCIS-DEV
            d = dict(HREFPAR)
            TITLE = d['title']
            ISBNS = d['isbn']
        #Cleans ISBNS to only conatian valid characters
            CISBN = clean(ISBNS)
        #V13 = validated canonical ISBN-13
            V13 = EAN13(CISBN)
            if V13 is None:
                V13 = canonical(CISBN)
            M = parse(HREF)

            print("GCIS-DEV\n\n\t", M, '\n\n\t', "isbn_original:", ISBNS, '\n\n\t', "isbn_mod:", V13, "\n\n")

        #DBpedia ISBN formats
            a = ISBNS
            b = canonical(CISBN)
            c = to_isbn10(CISBN)
            d = hyphenate(to_isbn10(CISBN))
            e = to_isbn13(CISBN)
            f = hyphenate(to_isbn13(CISBN))
            g = V13
            h = "ISBN {}" .format(CISBN)
            i = "ISBN {}" .format(canonical(CISBN))
            j = "ISBN {}" .format(hyphenate(to_isbn13(CISBN)))
            k = "ISBN {}" .format(V13)
            l = "ISBN {}" .format(to_isbn10(CISBN))
            m = "ISBN {}" .format(hyphenate(to_isbn10(CISBN)))

            tests = [a,b,c,d,e,f,g,h,i,j,k,l,m]

            for indie in tests:
                r = QUERY % indie
                RQUERY(r)
                if len(RQUERY(r)) != 0:
                    print(RQUERY(r))
                    break


        except:
            Error = '\n\t######## PROBLEM #######\n\tTitle:{}\n\tGCIS-ISBN:{}\n\tIdentifier:{}\n\n'.format(TITLE, ISBNS, IDEN)
            print(Error)
            file.write(Error)
Example #10
0
#!/usr/bin/python

#inport the library(s)
import isbn_hyphenate
import pyperclip

isbns = pyperclip.paste()
mylist = isbns.split(' ')

mylist[0].split(' ')
mylist[1].split(' ')
mylist[2].split(' ')

print "All ISBNs are now in your clipboard. The code below is simply for your review" + "\n"

print "<p class=\"isbn\">Print ISBN: " + isbn_hyphenate.hyphenate(mylist[0]) +"</p>"
print "<p class=\"isbn\">ePub ISBN: " + isbn_hyphenate.hyphenate(mylist[1]) +"</p>"
print "<p class=\"isbn\">Kindle ISBN: " + isbn_hyphenate.hyphenate(mylist[2]) +"</p>"


pyperclip.copy("<p class=\"isbn\">Print ISBN: " + isbn_hyphenate.hyphenate(mylist[0]) +"</p>" + "\n" + "<p class=\"isbn\">ePub ISBN: " + isbn_hyphenate.hyphenate(mylist[1]) +"</p>" + "\n" + "<p class=\"isbn\">Kindle ISBN: " + isbn_hyphenate.hyphenate(mylist[2]) +"</p>")
Example #11
0
        ("<p class=\"figure backcover\"", "\n\n<p class=\"figure backcover\""),
        # ("(<p class=\"subheading2\">.*[\r\n])(<p class=\"figure-tall img-holder\">.*[\r\n])", r"\2\1"),# ! OG MIDS
        # ("<p class=\"figure-tall img-holder\">.*$[\r\n])(^<p class=\"subheading2.*$[\r\n]", r"\2\1") #! TEST
    ]

    for pat, repl in replacement:
        text_to_search = re.sub(pat, repl, text_to_search)

    # * SAVE
    saveFile = open('workshop/index.html', 'w')
    saveFile.write(text_to_search)
    saveFile.close()

    # * Get HLDB from user to inject into a generic copyright page
    get_hldb_isbn = input("HLDB number: i.e. 9781705100219 ")
    HLDB_ISBN = isbn_hyphenate.hyphenate(get_hldb_isbn)

    # * Merge templates to index
    templates = [
        'templates/body01.xhtml', 'templates/body02.xhtml',
        'workshop/index.html', 'templates/body03.xhtml'
    ]

    with open('./workshop/output.xhtml', 'w') as outfile:
        for template in templates:
            with open(template) as infile:
                outfile.write(infile.read())
                outfile.write("\n")

    # * Clear out temp files move into final resting place
    os.remove("./workshop/index.html")
Example #12
0
 def test_hyphenating_known_values(self):
     for with_hyphens in self.knownValues:
         without_hyphens = with_hyphens.replace('-', '')
         self.assertEqual(isbn_hyphenate.hyphenate(without_hyphens),
                          with_hyphens)