feat: 帖子搜索 & 移除登录代码使用IP代理

This commit is contained in:
Relakkes
2024-08-06 03:37:55 +08:00
parent a87094f2fd
commit d347cf5a2c
8 changed files with 600 additions and 389 deletions

View File

@@ -22,31 +22,20 @@ class TieBaStoreFactory:
async def update_tieba_note(note_item: Dict):
tieba_url = "https://tieba.baidu.com"
note_id = note_item.get("note_id")
user_info = note_item.get("user", {})
interact_info = note_item.get("interact_info", {})
tag_list: List[Dict] = note_item.get("tag_list", [])
local_db_item = {
"note_id": note_id,
"type": note_item.get("type"),
"title": note_item.get("title") or note_item.get("desc", "")[:255],
"desc": note_item.get("desc", ""),
"note_url": tieba_url + note_item.get("note_url"),
"time": note_item.get("time"),
"last_update_time": note_item.get("last_update_time", 0),
"user_id": user_info.get("user_id"),
"nickname": user_info.get("nickname"),
"avatar": user_info.get("avatar"),
"liked_count": interact_info.get("liked_count"),
"collected_count": interact_info.get("collected_count"),
"comment_count": interact_info.get("comment_count"),
"share_count": interact_info.get("share_count"),
"tieba_name": note_item.get("tieba_name"),
"tieba_link": tieba_url + note_item.get("tieba_link", ""),
"nickname": note_item.get("nickname"),
"nickname_link": tieba_url + note_item.get("nickname_link", ""),
"ip_location": note_item.get("ip_location", ""),
"tag_list": ','.join([tag.get('name', '') for tag in tag_list if tag.get('type') == 'topic']),
"last_modify_ts": utils.get_current_timestamp(),
# todo: add note_url
"note_url": ""
}
utils.logger.info(f"[store.tieba.update_tieba_note] tieba note: {local_db_item}")
await TieBaStoreFactory.create_store().store_content(local_db_item)

View File

@@ -15,7 +15,7 @@ async def query_content_by_content_id(content_id: str) -> Dict:
"""
async_db_conn: AsyncMysqlDB = media_crawler_db_var.get()
sql: str = f"select * from baidu_tieba where note_id = '{content_id}'"
sql: str = f"select * from tieba_note where note_id = '{content_id}'"
rows: List[Dict] = await async_db_conn.query(sql)
if len(rows) > 0:
return rows[0]
@@ -32,7 +32,7 @@ async def add_new_content(content_item: Dict) -> int:
"""
async_db_conn: AsyncMysqlDB = media_crawler_db_var.get()
last_row_id: int = await async_db_conn.item_to_table("baidu_tieba", content_item)
last_row_id: int = await async_db_conn.item_to_table("tieba_note", content_item)
return last_row_id
@@ -47,7 +47,7 @@ async def update_content_by_content_id(content_id: str, content_item: Dict) -> i
"""
async_db_conn: AsyncMysqlDB = media_crawler_db_var.get()
effect_row: int = await async_db_conn.update_table("baidu_tieba", content_item, "note_id", content_id)
effect_row: int = await async_db_conn.update_table("tieba_note", content_item, "note_id", content_id)
return effect_row
@@ -62,7 +62,7 @@ async def query_comment_by_comment_id(comment_id: str) -> Dict:
"""
async_db_conn: AsyncMysqlDB = media_crawler_db_var.get()
sql: str = f"select * from baidu_tieba_comment where comment_id = '{comment_id}'"
sql: str = f"select * from tieba_comment where comment_id = '{comment_id}'"
rows: List[Dict] = await async_db_conn.query(sql)
if len(rows) > 0:
return rows[0]
@@ -79,7 +79,7 @@ async def add_new_comment(comment_item: Dict) -> int:
"""
async_db_conn: AsyncMysqlDB = media_crawler_db_var.get()
last_row_id: int = await async_db_conn.item_to_table("baidu_tieba_comment", comment_item)
last_row_id: int = await async_db_conn.item_to_table("tieba_comment", comment_item)
return last_row_id
@@ -94,7 +94,7 @@ async def update_comment_by_comment_id(comment_id: str, comment_item: Dict) -> i
"""
async_db_conn: AsyncMysqlDB = media_crawler_db_var.get()
effect_row: int = await async_db_conn.update_table("baidu_tieba_comment", comment_item, "comment_id", comment_id)
effect_row: int = await async_db_conn.update_table("tieba_comment", comment_item, "comment_id", comment_id)
return effect_row
@@ -108,7 +108,7 @@ async def query_creator_by_user_id(user_id: str) -> Dict:
"""
async_db_conn: AsyncMysqlDB = media_crawler_db_var.get()
sql: str = f"select * from baidu_tieba_creator where user_id = '{user_id}'"
sql: str = f"select * from tieba_creator where user_id = '{user_id}'"
rows: List[Dict] = await async_db_conn.query(sql)
if len(rows) > 0:
return rows[0]
@@ -125,7 +125,7 @@ async def add_new_creator(creator_item: Dict) -> int:
"""
async_db_conn: AsyncMysqlDB = media_crawler_db_var.get()
last_row_id: int = await async_db_conn.item_to_table("baidu_tieba_creator", creator_item)
last_row_id: int = await async_db_conn.item_to_table("tieba_creator", creator_item)
return last_row_id
@@ -140,5 +140,5 @@ async def update_creator_by_user_id(user_id: str, creator_item: Dict) -> int:
"""
async_db_conn: AsyncMysqlDB = media_crawler_db_var.get()
effect_row: int = await async_db_conn.update_table("baidu_tieba_creator", creator_item, "user_id", user_id)
effect_row: int = await async_db_conn.update_table("tieba_creator", creator_item, "user_id", user_id)
return effect_row