Display appropriate status message based on credit state.
(plan_credits: Optional[dict], purchased_credits: list, promo_credits: list)
| 77 | |
| 78 | |
| 79 | def _display_status_message(plan_credits: Optional[dict], purchased_credits: list, promo_credits: list) -> None: |
| 80 | """Display appropriate status message based on credit state.""" |
| 81 | has_remaining = False |
| 82 | |
| 83 | # Check if plan credits have remaining balance and are not expired |
| 84 | if plan_credits: |
| 85 | remaining = plan_credits["remaining"] |
| 86 | dt_str = plan_credits["period_end"].replace("Z", "+00:00") |
| 87 | period_end = datetime.fromisoformat(dt_str) |
| 88 | # If naive datetime, assume UTC |
| 89 | if period_end.tzinfo is None: |
| 90 | period_end = period_end.replace(tzinfo=timezone.utc) |
| 91 | now = datetime.now(timezone.utc) |
| 92 | |
| 93 | if remaining > 0 and period_end > now: |
| 94 | has_remaining = True |
| 95 | |
| 96 | # Check if any purchased or promo credits have remaining balance and not expired |
| 97 | for bucket in [*purchased_credits, *promo_credits]: |
| 98 | dt_str = bucket["expiry_date"].replace("Z", "+00:00") |
| 99 | expiry_date = datetime.fromisoformat(dt_str) |
| 100 | # If naive datetime, assume UTC |
| 101 | if expiry_date.tzinfo is None: |
| 102 | expiry_date = expiry_date.replace(tzinfo=timezone.utc) |
| 103 | now = datetime.now(timezone.utc) |
| 104 | |
| 105 | if bucket["remaining"] > 0 and expiry_date > now: |
| 106 | has_remaining = True |
| 107 | break |
| 108 | |
| 109 | if not has_remaining: |
| 110 | console.print("\nNo rendering credits remaining. Upgrade to continue rendering.") |
| 111 | |
| 112 | |
| 113 | def print_status(api_key: str, api_url: str, client_version: str) -> None: |
no outgoing calls