(argv: list[str])
| 432 | |
| 433 | |
| 434 | def main(argv: list[str]) -> int: |
| 435 | args = parse_args(argv) |
| 436 | today = dt.date.fromisoformat(args.today) if args.today else dt.date.today() |
| 437 | floor = dt.date.fromisoformat(args.floor) |
| 438 | requested_platforms = [p.strip() for p in args.platforms.split(",") if p.strip()] |
| 439 | blog_dir = Path(args.blog_dir) |
| 440 | state_file = Path(args.state_file) |
| 441 | |
| 442 | if args.dry_run: |
| 443 | platforms = requested_platforms |
| 444 | else: |
| 445 | platforms = [] |
| 446 | for platform in requested_platforms: |
| 447 | if is_platform_configured(platform): |
| 448 | platforms.append(platform) |
| 449 | else: |
| 450 | # Skipping an unconfigured platform here (instead of failing) keeps |
| 451 | # the candidate selector from getting stuck on a post that can never |
| 452 | # be fully syndicated. Once the missing creds appear, the next run |
| 453 | # picks up where this one left off. |
| 454 | print(f"[{platform}] credentials not configured; skipping platform.") |
| 455 | |
| 456 | if not platforms: |
| 457 | print("No platforms are configured; nothing to do.") |
| 458 | return 0 |
| 459 | |
| 460 | posts = discover_posts(blog_dir) |
| 461 | state = State.load(state_file) |
| 462 | candidate = select_candidate(posts, state, platforms, today, floor, args.min_age_days) |
| 463 | if candidate is None: |
| 464 | print("No syndication candidate found today.") |
| 465 | return 0 |
| 466 | |
| 467 | print(f"Selected post: {candidate.slug} (date={candidate.date.isoformat()})") |
| 468 | body_markdown = render_syndicated_body(candidate) |
| 469 | |
| 470 | any_change = False |
| 471 | failures: list[str] = [] |
| 472 | |
| 473 | for platform in platforms: |
| 474 | if state.is_syndicated(candidate.slug, platform): |
| 475 | print(f" [{platform}] already syndicated; skipping.") |
| 476 | continue |
| 477 | if args.dry_run: |
| 478 | print(f" [{platform}] dry run — would publish {len(body_markdown)} chars, canonical {candidate.canonical_url}") |
| 479 | continue |
| 480 | try: |
| 481 | if platform == "devto": |
| 482 | result = publish_to_devto( |
| 483 | candidate, body_markdown, os.environ["DEVTO_API_KEY"], |
| 484 | draft=args.draft_mode, |
| 485 | ) |
| 486 | else: |
| 487 | raise RuntimeError(f"unknown platform: {platform}") |
| 488 | except Exception as err: # noqa: BLE001 — surface any failure as per-platform |
| 489 | print(f" [{platform}] FAILED: {err}", file=sys.stderr) |
| 490 | failures.append(platform) |
| 491 | continue |
no test coverage detected