def import_top_order(): book_subject_data_path_top_order = os.path.join(os.getcwd(), 'utils/top_order中文.xlsx') xlsx = xlrd.open_workbook(book_subject_data_path_top_order) table = xlsx.sheets()[0] nrows = table.nrows ncols = table.ncols # 获取图书详细信息所有字段 for row_i in range(1, nrows): row = table.row_values(row_i) # row[0]如果空数据,类型为字符串,否则为float型 if not isinstance(row[0], str): abook = Book() abook.title = row[2] abook.title_cn = row[5] abook.author_name_str = row[3] abook.author_name_str_cn = row[6] abook.guten_id = int(row[1]) abook.guten_down_nums = row[4] # 封面图片路径 media/images_cover/ # 将爬取的图片放入此目录即可 # abook.cover_img = 'images_cover/' + abook.douban_subject_id + '.jpg' try: abook.save() except Exception as e: print(row_i, abook.title, e) continue else: print(row_i, row)
def test_book_unicode_method_when_there_is_an_empty_book(self): book = Book() title = book.__unicode__() self.assertEqual('', title)
def test_get_book_request_if_there_is_no_request(self): book_request = Book() usernames = book_request.get_book_request() self.assertEqual([], usernames)