()
| 335 | |
| 336 | |
| 337 | def main(): |
| 338 | parser = argparse.ArgumentParser(description="Fetch fulltext for knowledge base documents") |
| 339 | parser.add_argument("--framework", "-f", default="", help="Filter by framework (fda, eu_mdr, nmpa)") |
| 340 | parser.add_argument("--type", "-t", default="", help="Filter by document type (guidance, regulations)") |
| 341 | parser.add_argument("--id", default="", help="Process a specific document by ID") |
| 342 | parser.add_argument("--all", action="store_true", help="Process all documents") |
| 343 | parser.add_argument("--dry-run", action="store_true", help="Show what would be done without fetching") |
| 344 | parser.add_argument("--force", action="store_true", help="Re-fetch even if fulltext exists") |
| 345 | args = parser.parse_args() |
| 346 | |
| 347 | if not args.framework and not args.id and not args.all: |
| 348 | parser.print_help() |
| 349 | print("\nExamples:") |
| 350 | print(" python scripts/fetch_fulltext.py --framework fda --type guidance") |
| 351 | print(" python scripts/fetch_fulltext.py --id fda-cybersecurity-premarket-2026") |
| 352 | print(" python scripts/fetch_fulltext.py --all --dry-run") |
| 353 | return |
| 354 | |
| 355 | entries = load_entries( |
| 356 | framework=args.framework, |
| 357 | doc_type=args.type, |
| 358 | doc_id=args.id, |
| 359 | ) |
| 360 | |
| 361 | if not entries: |
| 362 | logger.info("No entries found matching criteria.") |
| 363 | return |
| 364 | |
| 365 | logger.info(f"Found {len(entries)} entries to process") |
| 366 | |
| 367 | success = 0 |
| 368 | skipped = 0 |
| 369 | failed = 0 |
| 370 | |
| 371 | for entry in entries: |
| 372 | if not args.force and fulltext_exists(entry): |
| 373 | skipped += 1 |
| 374 | continue |
| 375 | |
| 376 | try: |
| 377 | ok = process_entry(entry, dry_run=args.dry_run) |
| 378 | if ok: |
| 379 | success += 1 |
| 380 | else: |
| 381 | skipped += 1 |
| 382 | except Exception as e: |
| 383 | logger.error(f" EXCEPTION: {e}") |
| 384 | failed += 1 |
| 385 | |
| 386 | time.sleep(1) |
| 387 | |
| 388 | logger.info(f"\nSummary: {success} processed, {skipped} skipped, {failed} failed (total: {len(entries)})") |
| 389 | |
| 390 | |
| 391 | if __name__ == "__main__": |
no test coverage detected