()
| 347 | |
| 348 | |
| 349 | def process_candidates() -> tuple[int, int, int, list[str], list[str], list[str], int]: |
| 350 | run_date = today() |
| 351 | candidates_data = load_json(CANDIDATES_PATH) |
| 352 | entries_data = load_json(ENTRIES_PATH) |
| 353 | entries = entries_data.get("entries") |
| 354 | candidates = candidates_data.get("candidates") |
| 355 | if not isinstance(entries, list): |
| 356 | raise ValueError("data/entries.json must contain an entries array") |
| 357 | if not isinstance(candidates, list): |
| 358 | raise ValueError("data/candidates.json must contain a candidates array") |
| 359 | |
| 360 | for entry in entries: |
| 361 | entry["category"] = normalize_category(entry.get("category")) |
| 362 | entries, removed_duplicates = dedupe_entries(entries) |
| 363 | category_ids = {str(category.get("id")) for category in entries_data.get("categories", []) if isinstance(category, dict)} |
| 364 | accepted_names: list[str] = [] |
| 365 | skipped_names: list[str] = [] |
| 366 | errors: list[str] = [] |
| 367 | |
| 368 | for candidate in candidates: |
| 369 | if not isinstance(candidate, dict): |
| 370 | errors.append("候选结构不是对象") |
| 371 | continue |
| 372 | candidate_name = str(candidate.get("name") or candidate.get("id") or "unnamed").strip() |
| 373 | try: |
| 374 | existing_match = next( |
| 375 | ((i, entry, duplicate_reason(candidate, entry)) for i, entry in enumerate(entries) if duplicate_reason(candidate, entry)), |
| 376 | None, |
| 377 | ) |
| 378 | if existing_match: |
| 379 | _, existing, duplicate = existing_match |
| 380 | existing_readme_ok, _ = readme_update_decision(existing, category_ids) |
| 381 | if existing_readme_ok: |
| 382 | skipped_names.append(f"{candidate_name}({duplicate})") |
| 383 | continue |
| 384 | should_accept, reason = candidate_decision(candidate) |
| 385 | if not should_accept: |
| 386 | skipped_names.append(f"{candidate_name}({reason})") |
| 387 | continue |
| 388 | readme_ok, readme_reason = readme_update_decision(candidate, category_ids) |
| 389 | if not readme_ok: |
| 390 | skipped_names.append(f"{candidate_name}(不更新README:{readme_reason})") |
| 391 | continue |
| 392 | new_entry = entry_from_candidate(candidate, run_date, readme_reason) |
| 393 | if existing_match: |
| 394 | index, _, duplicate = existing_match |
| 395 | entries[index] = new_entry |
| 396 | accepted_names.append(f"{candidate_name}(升级{duplicate})") |
| 397 | continue |
| 398 | entries.insert(0, new_entry) |
| 399 | accepted_names.append(candidate_name) |
| 400 | except Exception as exc: # noqa: BLE001 |
| 401 | errors.append(f"{candidate_name}({exc})") |
| 402 | |
| 403 | entries_data["entries"] = entries |
| 404 | entries_data["updated"] = run_date |
| 405 | candidates_data["processed_count"] = int(candidates_data.get("processed_count") or 0) + len(candidates) |
| 406 | candidates_data["processed_date"] = run_date if candidates else candidates_data.get("processed_date", run_date) |
no test coverage detected