Beispiel #1
0
def book_input_auto():
    book_list = get_data('book_out.txt')
    from book.models import Book
    from book.models import Taxonomy
    
    for b in book_list:
        bs = None
        if b[6] != '':
            bs = Book.objects.filter(isbn=b[6]) 
        if bs is None or not bs.exists():
            bs = Book.objects.filter(name=b[0], version=b[7]) 
            if not bs.exists():
                try:
                    book = Book()
                    book.name = b[0]
                    book.subtitle = b[1]
                    if b[2] is None:
                        book.author = ''
                    else:
                        book.author = b[2]
                    if b[3] is None:
                        book.press = ''
                    else:
                        book.press = b[3]
                    book.price_ori = b[4]
                    if b[5] is None or b[5] == 0:
                        book.price_now = 0.4*b[4]
                    else:
                        book.price_now = b[5]
                    book.isbn = b[6]
                    book.version = b[7]
                    book.publication_date = b[8]
                    book.page_number = b[9]
                    book.size = b[10]
                    book.binding = b[11]
                    if b[12] == 'zh':
                        book.language = 'zh'
                    else:
                        book.language = 'en'
                    if b[13] is None:
                        book.translator = ''
                    else:
                        book.translator = b[13]
                    book.status = 4
                    book.save()
                    try:
                        if b[14] is not None and b[14] != '':
                            t = Taxonomy.objects.get(name=TAXONOMY_DICT[b[13]])
                            book.add_taxonomy(t)
                    except Exception, e:
                        print "Add taxonomy failed"
                        print e
                        print book_list.index(b)
                        print b
                        import pdb;pdb.set_trace()
                except Exception, e:
                    print e
                    print book_list.index(b)
                    print b