Esempio n. 1
0
def isbn_post(form):
    cgiutil.print_header('책 등록', 'style.css')
    print '<p>'
    print_progress('LibraryThing에 로그인합니다')
    api = ltapi.signup(account.username, account.password)
    if not api:
        print '실패했습니다.<br>'
        print '</p>'
        return
    print_progress('책을 등록합니다')
    api.update(form)
    isbn = form.getvalue('isbn')
    print_progress('방금 등록한 책의 ID를 가져옵니다')
    bookid = api.get_bookid(isbn)
    print_info('bookid', bookid)
    print_progress('표지를 올립니다')
    cover = form.getvalue('cover')
    api.set_cover(bookid, cover)
    authorid = form.getvalue('authorid')
    workid = form.getvalue('workid')
    thisid = ltapi.get_lastpart(ltapi.link_isbn(isbn))
    if workid:
        print_progress('책을 원서와 엮을 준비를 합니다')
        title = form.getvalue('title')
        worktitle = cgiutil.encode(api.get_worktitle(bookid))
        print_info('title', title)
        print_info('worktitle', worktitle)
        if title != worktitle:
            print '책이 이미 엮여 있습니다.<br>'
        else:
            print_info('authorid', authorid)
            print_info('workid', workid)
            print_info('thisid', thisid)
            print_progress('책을 엮습니다')
            api.work_combine(authorid, workid, thisid)
    else:
        print '책을 엮지 않습니다.<br>'
    url = 'http://www.librarything.com/work/%s/details/%s' % (thisid, bookid)
    print '<a href="%s">등록되었습니다</a>.<br>' % (url,)
    print '</p>'
    return_link()
    cgiutil.print_footer()
Esempio n. 2
0
def do_isbn_query(isbn):
    print '<p>'
    print_info('ISBN', isbn, 'isbn')
    if not isbntool.validate(isbn):
        print '올바른 ISBN이 아닙니다.<br>'
        print '</p>'
        return
    lang = ltapi.thingLang(isbn)
    print_info('언어', lang, 'lang')
    print '</p>'

    print '<p>'
    print_progress('LibraryThing에 등록되어 있는지 확인합니다')

    if ltapi.thingISBN(isbn):
        url = ltapi.link_isbn(isbn)
        print '<a href="%s">이미 있습니다</a>.<br>' % (url,)
        print '</p>'
        return
    else:
        print '아직 없습니다.<br>'
        print '</p>'

    print '<p>'
    print_progress('네이버에서 책 정보를 검색합니다')

    api = naver.NaverOpenAPI(account.apikey['naver'])
    book = api.book(isbn)
    if book:
        title = cgiutil.encode(book.title())
        publication = cgiutil.encode(book.publication())
        print_info('제목', title, 'title')
        print_info('출판사', publication, 'publication')
        date = book.date()
        hidden_input('date', date)
        print '</p>'
    else:
        print '없습니다.<br>'
        print '</p>'
        return

    print '<p>'
    print_progress('책 표지를 검색합니다')

    cover = None
    naver_cover = book.cover()
    if naver_cover:
        print '네이버'
        print '<img src="%s" alt="네이버 표지">' % (naver_cover,)
        cover = naver_cover
    aladdin_cover = aladdin.cover(isbn)
    if aladdin_cover:
        print '알라딘'
        print '<img src="%s" alt="알라딘 표지">' % (aladdin_cover,)
        cover = aladdin_cover
    print '<br>'
    if cover:
        hidden_input('cover', cover)
    print '</p>'

    cgiutil.next_cell()

    original_title = None
    for server in zinfo.servers:
        result = z3950_query(server, isbn)
        if result:
            original_title, author = result
            break
    if not original_title:
        return

    print '<p>'
    print_progress('원서명으로 LibraryThing을 검색합니다')

    url = ltapi.link_title(original_title)
    if url:
        print '<a href="%s">%s</a>' % (url, original_title),
        author_url = ltapi.link_author(author)
        print 'by <a href="%s">%s</a>.<br>' % (author_url, author)
        hidden_input('workid', ltapi.get_lastpart(url))
        hidden_input('authorid', ltapi.get_lastpart(author_url))
        print '</p>'
    else:
        print '없습니다.<br>'
        print '</p>'

    print '<p>'
    print '<input type="submit" value="등록">'
    print '</p>'