|
@@ -74,14 +74,13 @@ def upsert_good_authors(
|
|
|
if not accounts:
|
|
if not accounts:
|
|
|
return 0
|
|
return 0
|
|
|
|
|
|
|
|
- sql = """
|
|
|
|
|
- INSERT INTO demand_find_author (trace_id, author_name, author_link, elderly_ratio, elderly_tgi, remark, content_tags)
|
|
|
|
|
- VALUES (%s, %s, %s, %s, %s, %s, %s)
|
|
|
|
|
- ON DUPLICATE KEY UPDATE
|
|
|
|
|
- elderly_ratio = VALUES(elderly_ratio),
|
|
|
|
|
- elderly_tgi = VALUES(elderly_tgi),
|
|
|
|
|
- remark = VALUES(remark)
|
|
|
|
|
|
|
+ insert_sql = """
|
|
|
|
|
+ INSERT INTO demand_find_author (
|
|
|
|
|
+ trace_id, channel, author_id, author_name, author_link, elderly_ratio, elderly_tgi, remark, content_tags
|
|
|
|
|
+ )
|
|
|
|
|
+ VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)
|
|
|
"""
|
|
"""
|
|
|
|
|
+ exists_sql = "SELECT 1 FROM demand_find_author WHERE author_id = %s LIMIT 1"
|
|
|
with conn.cursor() as cur:
|
|
with conn.cursor() as cur:
|
|
|
rows = 0
|
|
rows = 0
|
|
|
for acc in accounts:
|
|
for acc in accounts:
|
|
@@ -96,17 +95,26 @@ def upsert_good_authors(
|
|
|
sec_uid = acc.get("author_sec_uid") or acc.get("sec_uid")
|
|
sec_uid = acc.get("author_sec_uid") or acc.get("sec_uid")
|
|
|
if not author_link and sec_uid:
|
|
if not author_link and sec_uid:
|
|
|
author_link = f"https://www.douyin.com/user/{sec_uid}"
|
|
author_link = f"https://www.douyin.com/user/{sec_uid}"
|
|
|
- if not author_name or not author_link:
|
|
|
|
|
|
|
+ author_id = str(sec_uid).strip() if sec_uid is not None else ""
|
|
|
|
|
+ if not author_name or not author_link or not author_id:
|
|
|
continue
|
|
continue
|
|
|
|
|
|
|
|
elderly_ratio = acc.get("age_50_plus_ratio") or ""
|
|
elderly_ratio = acc.get("age_50_plus_ratio") or ""
|
|
|
elderly_tgi = acc.get("age_50_plus_tgi") or ""
|
|
elderly_tgi = acc.get("age_50_plus_tgi") or ""
|
|
|
remark = acc.get("reason") or acc.get("remark") or ""
|
|
remark = acc.get("reason") or acc.get("remark") or ""
|
|
|
content_tags = _normalize_content_tags(acc.get("content_tags"))
|
|
content_tags = _normalize_content_tags(acc.get("content_tags"))
|
|
|
|
|
+
|
|
|
|
|
+ # author_id 已存在时跳过,避免重复新增
|
|
|
|
|
+ cur.execute(exists_sql, (author_id,))
|
|
|
|
|
+ if cur.fetchone():
|
|
|
|
|
+ continue
|
|
|
|
|
+
|
|
|
cur.execute(
|
|
cur.execute(
|
|
|
- sql,
|
|
|
|
|
|
|
+ insert_sql,
|
|
|
(
|
|
(
|
|
|
trace_id,
|
|
trace_id,
|
|
|
|
|
+ "抖音",
|
|
|
|
|
+ author_id,
|
|
|
author_name,
|
|
author_name,
|
|
|
author_link,
|
|
author_link,
|
|
|
str(elderly_ratio) if elderly_ratio is not None else None,
|
|
str(elderly_ratio) if elderly_ratio is not None else None,
|