Returns the total usage for a profile. Reads directly from file (blocking), suitable for auth rotation logic which might run in sync context or low frequency. For high frequency, consider caching. Includes fallback logic to find usage by filename if absolute path doesn't match (hand
(profile_path: str)
| 70 | |
| 71 | |
| 72 | def get_profile_usage(profile_path: str) -> int: |
| 73 | """ |
| 74 | Returns the total usage for a profile. |
| 75 | Reads directly from file (blocking), suitable for auth rotation logic which might run in sync context or low frequency. |
| 76 | For high frequency, consider caching. |
| 77 | Includes fallback logic to find usage by filename if absolute path doesn't match (handles moved files). |
| 78 | """ |
| 79 | profile_path = os.path.abspath(profile_path) |
| 80 | usage_data = _load_usage_data() |
| 81 | |
| 82 | # Direct match |
| 83 | if profile_path in usage_data: |
| 84 | return usage_data[profile_path] |
| 85 | |
| 86 | # Fallback: Match by filename |
| 87 | # This handles cases where files are moved (e.g. saved -> emergency) but usage data has old path |
| 88 | profile_basename = os.path.basename(profile_path) |
| 89 | for key, usage in usage_data.items(): |
| 90 | if os.path.basename(key) == profile_basename: |
| 91 | return usage |
| 92 | |
| 93 | return 0 |
no test coverage detected