modify scripts
This commit is contained in:
@ -25,7 +25,8 @@ def fetch_book_list():
|
||||
# 获取书籍列表
|
||||
list_data, next_url = scraper.parse_book_list(soup, url=url)
|
||||
for item in list_data:
|
||||
row_id = db_tools.insert_or_update_common(item, db_tools.tbl_name_books)
|
||||
#row_id = db_tools.insert_or_update_common(item, db_tools.tbl_name_books)
|
||||
row_id = db_tools.insert_books_index(item)
|
||||
if row_id:
|
||||
logging.debug(f"insert one book. row_id: {row_id}, name: {item['name']}")
|
||||
else:
|
||||
|
||||
@ -130,10 +130,11 @@ def insert_or_update_common_lower(data, tbl_name, uniq_key='href'):
|
||||
def insert_books_index(data):
|
||||
try:
|
||||
# 查询是否存在以及是否需要更新
|
||||
cursor.execute(f"SELECT id FROM books WHERE href = ? and update_time >= ?", (data['href'], data['update_time'], ))
|
||||
cursor.execute(f"SELECT id FROM {tbl_name_books} WHERE href = ? and update_time >= ?", (data['href'], data['update_time'], ))
|
||||
existing_book = cursor.fetchone()
|
||||
|
||||
if existing_book: # **如果演员已存在**
|
||||
logging.debug(f"book {data['href']} already exist. id: {existing_book[0]}")
|
||||
return existing_book[0]
|
||||
|
||||
# 不存在,或者需要更新
|
||||
|
||||
Reference in New Issue
Block a user