Created
January 17, 2025 09:17
-
-
Save RoCry/7380f6b83cde6d8a9a0254a3c6fe0e20 to your computer and use it in GitHub Desktop.
cursor_usage.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
def get_cookie() -> str: | |
import browser_cookie3 | |
return browser_cookie3.arc(domain_name="cursor.com") | |
def req(url: str, cookies: list[str]) -> requests.Response: | |
headers = { | |
"accept": "*/*", | |
"accept-language": "en-US,en;q=0.9,zh;q=0.8,zh-HK;q=0.7,zh-TW;q=0.6", | |
"dnt": "1", | |
"priority": "u=1, i", | |
"referer": "https://www.cursor.com/settings", | |
"sec-ch-ua": '"Chromium";v="131", "Not_A Brand";v="24"', | |
"sec-ch-ua-mobile": "?0", | |
"sec-ch-ua-platform": '"macOS"', | |
"sec-fetch-dest": "empty", | |
"sec-fetch-mode": "cors", | |
"sec-fetch-site": "same-origin", | |
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36", | |
} | |
return requests.get(url, headers=headers, cookies=cookies) | |
def print_usage(user_id: str, show_small: bool = False): | |
resp = req(f"https://www.cursor.com/api/usage?user={user_id}", get_cookie()) | |
data = resp.json() | |
preminum = ( | |
f"{data['gpt-4']['numRequestsTotal']} / {data['gpt-4']['maxRequestUsage']}" | |
) | |
if show_small: | |
small = f"{data['gpt-3.5-turbo']['numRequestsTotal']} / {data['gpt-3.5-turbo'].get('maxRequestUsage') or 'No Limit'}" | |
print(f"Premium: {preminum}, small: {small}") | |
else: | |
print(f"Premium: {preminum}") | |
if __name__ == "__main__": | |
print_usage("user_01J68RXCAB64YCKP8FQ55Z010H") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment