Untitled
unknown
python
a year ago
3.3 kB
200
No Index
import requests
import time
from random import uniform
def get_api_keys():
print("Enter API keys (one per line, press Enter twice to finish):")
keys = []
while True:
key = input().strip()
if not key:
break
keys.append(key)
return keys
def convert_to_usd(amount, currency):
if currency == "CNY":
return float(amount) / 7.3
return float(amount)
def check_balance(api_keys):
url = "https://api.deepseek.com/user/balance"
valid_keys = []
keys_with_balance = []
total_usd = 0.0
for key in api_keys:
headers = {
'Accept': 'application/json',
'Authorization': f'Bearer {key}'
}
try:
response = requests.get(url, headers=headers)
if response.status_code == 401:
print(f"Invalid key: {key}")
time.sleep(uniform(1, 2)) # Random delay between 1-2 seconds
continue
elif response.status_code == 402:
print(f"No balance: {key}")
continue
elif response.status_code == 200:
data = response.json()
if data.get("is_available"):
for balance_info in data.get("balance_infos", []):
currency = balance_info.get('currency')
balance = float(balance_info.get('total_balance', 0))
usd_balance = convert_to_usd(balance, currency)
total_usd += usd_balance
print(f"\nValid key found: {key}")
print(f"Currency: {currency}")
print(f"Balance: {balance}")
print(f"USD Value: ${usd_balance:.2f}")
valid_keys.append((key, balance_info, usd_balance))
# Check if USD balance is greater than .8
if usd_balance > 0.8:
keys_with_balance.append(key)
except requests.exceptions.RequestException as e:
print(f"Error checking key {key}: {str(e)}")
time.sleep(uniform(1, 2))
return valid_keys, keys_with_balance, total_usd
def main():
api_keys = get_api_keys()
print("\nChecking API keys...\n")
valid_keys, keys_with_balance, total_usd = check_balance(api_keys)
if valid_keys:
print("\nSummary of valid keys with balance:")
for key, balance_info, usd_balance in valid_keys:
print(f"API Key: {key}")
print(f"Currency: {balance_info.get('currency')}")
print(f"Balance: {balance_info.get('total_balance')}")
print(f"USD Value: ${usd_balance:.2f}\n")
else:
print("\nNo valid keys with balance found.")
# Print comma-separated list of keys with balance > 0.8 USD
if keys_with_balance:
print("\nKeys with balance > $.8 USD:")
print(",".join(keys_with_balance))
else:
print("\nNo keys found with balance greater than $.8 USD.")
# Print total USD value
print(f"\nTotal USD value of all keys: ${total_usd:.2f}")
if __name__ == "__main__":
main()
Editor is loading...
Leave a Comment