Display a credit bucket line (purchased or promo) with progress bar.
(bucket: dict, label: str)
| 51 | |
| 52 | |
| 53 | def _display_bucket_credit_line(bucket: dict, label: str) -> None: |
| 54 | """Display a credit bucket line (purchased or promo) with progress bar.""" |
| 55 | remaining = bucket["remaining"] |
| 56 | total = bucket["total"] |
| 57 | expiry_date = bucket["expiry_date"] |
| 58 | |
| 59 | # Parse ISO-8601 timestamp and handle both with and without timezone info |
| 60 | dt_str = expiry_date.replace("Z", "+00:00") |
| 61 | dt = datetime.fromisoformat(dt_str) |
| 62 | # If naive datetime, assume UTC |
| 63 | if dt.tzinfo is None: |
| 64 | dt = dt.replace(tzinfo=timezone.utc) |
| 65 | formatted_date = dt.strftime("%b %-d, %Y") |
| 66 | |
| 67 | # Check if expired |
| 68 | now = datetime.now(timezone.utc) |
| 69 | is_expired = dt < now |
| 70 | |
| 71 | bar = _create_progress_bar(remaining, total, width=30) |
| 72 | |
| 73 | if is_expired: |
| 74 | console.print(f" {label:10} {bar} expired {formatted_date}") |
| 75 | else: |
| 76 | console.print(f" {label:10} {bar} {remaining:2} of {total} remaining expires {formatted_date}") |
| 77 | |
| 78 | |
| 79 | def _display_status_message(plan_credits: Optional[dict], purchased_credits: list, promo_credits: list) -> None: |