|
@@ -71,9 +71,36 @@ class JsonApiClient:
|
|
|
return context
|
|
return context
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def _extract_douyin_word_list_items(inner: dict[str, Any]) -> list[dict[str, Any]]:
|
|
|
|
|
+ word_list = inner.get("word_list")
|
|
|
|
|
+ if not isinstance(word_list, list):
|
|
|
|
|
+ return []
|
|
|
|
|
+
|
|
|
|
|
+ result: list[dict[str, Any]] = []
|
|
|
|
|
+ for item in word_list:
|
|
|
|
|
+ if not isinstance(item, dict):
|
|
|
|
|
+ continue
|
|
|
|
|
+ word = str(item.get("word") or "").strip()
|
|
|
|
|
+ if not word:
|
|
|
|
|
+ continue
|
|
|
|
|
+ normalized = dict(item)
|
|
|
|
|
+ normalized["title"] = word
|
|
|
|
|
+ position = item.get("position")
|
|
|
|
|
+ if position is not None:
|
|
|
|
|
+ normalized["rank"] = position
|
|
|
|
|
+ result.append(normalized)
|
|
|
|
|
+ return result
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def extract_rank_items(resp: dict[str, Any], source: str) -> list[dict[str, Any]]:
|
|
def extract_rank_items(resp: dict[str, Any], source: str) -> list[dict[str, Any]]:
|
|
|
data = resp.get("data") or {}
|
|
data = resp.get("data") or {}
|
|
|
- rows = data.get("data") if isinstance(data, dict) else data
|
|
|
|
|
|
|
+ inner = data.get("data") if isinstance(data, dict) else None
|
|
|
|
|
+ if isinstance(inner, dict):
|
|
|
|
|
+ douyin_items = _extract_douyin_word_list_items(inner)
|
|
|
|
|
+ if douyin_items:
|
|
|
|
|
+ return douyin_items
|
|
|
|
|
+
|
|
|
|
|
+ rows = inner if isinstance(inner, list) else data
|
|
|
if not isinstance(rows, list):
|
|
if not isinstance(rows, list):
|
|
|
return []
|
|
return []
|
|
|
|
|
|